/****************************************************************************
* Description	:	This is the common javascript file
*			which has different functions with their
*			definitions.
*
* Author	: Raghava K
* Date	: 24 Sep 2008
*
* Revision	:
* Modified By	: V S Prasad Vasamsetty
* Modified Date: 02 October 2008
* Reason	: xxxxxx
* USAGE:
*	element/fieldname – name of the control like frm.password.
*	Msg – Field Name that we want to display in alert message.
****************************************************************************/

/************************ To validate credit card *********************/
function isValidCreditCard(type, ccnum) {
   if (type == "Visa") {
      // Visa: length 16, prefix 4, dashes optional.
      var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "MasterCard") {
      // Mastercard: length 16, prefix 51-55, dashes optional.
      var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "Discover") {
      // Discover: length 16, prefix 6011, dashes optional.
      var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "AmericanExpress") {
      // American Express: length 15, prefix 34 or 37.
      var re = /^3[4,7]\d{13}$/;
   } else if (type == "Diners") {
      // Diners: length 14, prefix 30, 36, or 38.
      var re = /^3[0,6,8]\d{12}$/;
   }
   if (!re.test(ccnum)) return false;
   // Remove all dashes for the checksum checks to eliminate negative numbers
   ccnum = ccnum.split(" ").join("");
   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.
   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {

      checksum += parseInt(ccnum.charAt(i-1));
   }
   // Analyze odd digits in even length strings or even digits in odd length strings.
   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }
   if ((checksum % 10) == 0) return true; else return false;
}
/************************ To validate credit card *********************/

/************************ To validate name *********************/
function isValidname(element,msg)
{
//	alert(element.value);
	if(element.value.length == 0 )
	{
		alert("Please Enter the "+msg);
		element.focus();
		return false;
	}//if
	else
	{
		/*if(element.value.length < 6)
		{
			alert("Username should be Minimum of 6 Characters !");
			element.focus();
			return false;
		}*/
		var reg = /[\+\-\.\*\!\@\#\$\%\^\&\(\)\|0-9]+/;
		if(element.value.match(reg) != null)
		{
			alert("Invalid Entry in "+msg);
			element.focus();
			return false;
		}	
	}//else
	return true;
}//isValidname function
/************************ To validate name *********************/

/************************ To validate Password *********************/
function isPassword(element,msg)
{
	if(element.value.length==0 || element.value=='Password')
	{
		alert("Please Enter the "+msg);
		element.focus();
		return false;
	}//if
	/*else
	{
		if(element.value.length < 6)
		{
			alert("Password should be Minimum 6 Characters !");
			element.focus();
			return false;
		}
		var regpwd = /[\+\-\.\*\!\@\#\$\%\^\&\(\)\|]+/;
		if(element.value.match(regpwd) != null)
		{
			alert("Invalid Entry in "+msg);
			element.focus();
			return false;
		}	
	}//else*/
	return true;
}/// ispassword() closed
/************************ To validate Password *********************/

/************************ To check passwords match *********************/
function isPasswordMatch(element1,element2)
{
	if(element1.value!=element2.value)
	{
		alert("Password doesnot match !");
		element2.focus();
		return false;
	}
	return true;
}//// password match function closed
/************************ To check passwords match *********************/

/************************ To check username match *********************/
function isUserNameMatch(element1,element2)
{
	if(element1.value!=element2.value)
	{
		alert("Username doesnot match !");
		element2.focus();
		return false;
	}
	return true;
}//// username match function closed
/************************ To check username match *********************/


/************************ To validate Numeric field *********************/
function isValidFloat(element,msg)
{
	if(element.value.length == 0)
	{
		alert("Please Enter "+msg);
		element.focus();
		return false;
	}///if 
	else
	{
		var regnum = new RegExp("^[0-9]\.+$");
		if(!(element.value.match(regnum)))
		{
			alert("Invalid Entry in "+msg);
			element.focus();
			return false;
		}	
	}/// else closed
	return true;
} //isValidFloat() closed

/************************ To validate Numeric field *********************/
function isValidNumber(element,msg)
{
	if(element.value.length == 0)
	{
		alert("Please Enter "+msg);
		element.focus();
		return false;
	}///if 
	else
	{
		var regnum = new RegExp("^[0-9]+$");
		if(!(element.value.match(regnum)))
		{
			alert("Invalid Entry in "+msg);
			element.focus();
			return false;
		}	
	}/// else closed
	return true;
} //isValidNumber() closed

function isValidNo(element,msg)
{
	if(element.value.length == 0)
	{
		alert("Please Enter the "+msg);
		element.focus();
		return false;
	}///if 
	else
	{
		var regnum = new RegExp("^[0-9]");
		if(!(element.value.match(regnum)) || element.value.length < 2)
		{
			alert("Invalid Entry in "+msg);
			element.focus();
			return false;
		}		
	}/// else closed
	return true;
} //isValidNo() closed

/************************ To validate Numeric field *********************/

/************************ To validate input text *********************/
function isEmpty(element,msg)
{
	if(element.value.length == 0)
	{
		alert("Please Enter the "+ msg);
		element.focus();
		return false;
	}//// if
	else
	{
		var regname = /[\+\-\.\*\!\@\#\$\%\^\&\(\)\|]+/;
		if(element.value.match(regname) != null)
		{
			alert("Invalid Entry in "+msg);
			element.focus();
			return false;
		}
	}/// else
	return true;
}//// function IsEmpty() closed
/************************ To validate input text *********************/

/************************ To check for non-empty *********************/
function isEmpty1(element,msg)
{
	if(element.value == '')
	{
		alert("Please Enter the "+ msg);
		element.focus();
		return false;
	}//// if
	return true;
}//IsEmpty1() closed
/************************ To check for non-empty *********************/


/************************ To validate Email *********************/
function isValidEmail(element,msg)
{
	if(element.value.length==0 || element.value=='Email')
	{
		alert("Please Enter the "+msg);
		element.focus();
		return false;
	}///if 
	else
	{
		var regemail = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(!element.value.match(regemail))
		{
			alert("Invalid "+msg);
			element.focus();
			return false;
		}		
	}//// else
   return true;
}// isValidEmail() closed

function isValidEmail1(fieldName,msg)
{
	if(fieldName.value=="")
		return true;
	else 
	{
		if(!isValidEmail(fieldName,msg))
		return false;
	}
	return true;
}//isValidEmail1() closed

/************************ To check Emails match *********************/
function isEmailMatch(element1,element2)
{
	if(element1.value!=element2.value)
	{
		alert("Email doesnot match !");
		element2.focus();
		return false;
	}
	return true;
}//// Email match function closed
/************************ To check Emails match *********************/

function isAnyoneEmpty(fieldname1,fieldname2)
{
	if(fieldname1.value=="" && fieldname2.value=="")
	{
		alert("Please enter User Name or Email address!");
		fieldname1.focus();
		return false;
	}
	else
	{
		/*if(fieldname1.value !="" && fieldname2.value=="")
		{
			if(!isValidName(fieldname1,"User Name"))
				return false;
		}	*/
		if(fieldname1.value=="" && fieldname2.value!="")
		{
			if(!isValidEmail(fieldname2,"Invalid E-Mail"))
				return false;
		}
	}
	return true;
}
/************************ To validate Email *********************/

/************************ To validate Select field *********************/
function isSelect(element,msg)
{
	if(element.value=="")
	{
		alert("Please Select "+ msg +" from the List");
		element.focus();
		return false;
	}//if
	return true;
}/// isselect function clsed

function isSelected(element,msg)
{
	if(element.value=="0")
	{
		alert("Please select "+msg+" from the list");
		element.focus();
		return false;
	}
	return true;
}
/************************ To validate Select field *********************/


function isValidName2(fieldName1,fieldName2,msg)
{
	if(fieldName1.value != "")
	{
		var name_expr = /[\+\-\.\*\!\@\#\$\%\^\&\(\)\|]+/;
		if(fieldName2.value == "")
		{
			alert("Please enter "+msg);
			fieldName2.focus();
			return false;
		}
		else if(fieldName2.value.match(name_expr) != null) 
		{
			alert("Invalid " + msg);
			fieldName2.focus();
			return false;
		}
	}
	return true;
}

/************************ To validate radio button 08 SEPTEMBER 2008*********************/
function isValidoption(element,msg)
{
var radioLength = frm.elements["login[reg_user]"].length;   
//alert(radioLength);
	var flag = '';
    for(var i = 0; i < radioLength; i++) {
       if(frm.elements["login[reg_user]"][i].checked == true ) {
		   flag = 'found';
      break;
       }
    }	
//alert(flag);
}

/*function isValidMessageCount(fieldName,count,msg)
{
	if(fieldName.value.length < count)
	{
			alert(msg);
			fieldName.focus();
			return false;
	}
	return true;
}


function isValidMessageCount(fieldName,count)
{
	if(fieldName.value.length < count)
	{
		alert("You have to enter minimum of 100 characters");
		fieldName.focus();
		return false;
	}
	return true;
}*/

// function to add the current web page to Bookmark list
function bookmarkthispage() 
{ 
//	window.external.AddFavorite(location.href,document.title); 
	var title = window.location ; 
	var url = location.href; 
	if (window.sidebar)  
	{ // Mozilla Firefox Bookmark 
		window.sidebar.addPanel(title, url,""); 
	} 
	else if( window.external )  
	{ // IE Favorite 
		window.external.AddFavorite( url, title);  
	} 
	else if(window.opera && window.print) 
	{ // Opera Hotlist 
		return true;  
	}  
}

// function to print the current web page
var addPrintLink = {
	init:function(sTargetEl,sLinkText) {
		//alert('print');
		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
		if (!document.getElementById(sTargetEl)) {return;} // Check that the target element actually exists
		if (!window.print) {return;} // Check that the browser supports window.print
		var oTarget = document.getElementById(sTargetEl);
		var oLink = document.createElement('a');
		oLink.id = 'print-link'; // Give the link an id to allow styling
		oLink.href = '#'; // Make the link focusable for keyboard users
		oLink.appendChild(document.createTextNode(sLinkText));
		oLink.onclick = function() {window.print(); return false;} // Return false prevents the browser from following the link and jumping to the top of the page after printing
		oTarget.appendChild(oLink);
	},
	addEvent:function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
addPrintLink.addEvent(window, 'load', function(){addPrintLink.init('article','Print this page');});

// function for testimonial search in the current web page
function testimonial_search(searchterm)
{
	var arr_obj = new Array();
	var postcode = new Array();
	
	arr_obj[0] = "<tr><td height=\"5\" valign=\"top\" class=\"body_font\" align=\"left\"><p><strong><img src=\"images/brown.jpg\" alt=\"\" width=\"300\" height=\"225\" align=\"right\" class=\"img_border\" style=\"margin-left:5px;\">February 23, 2003</strong><br />Your goal is to grow as a business. We feel like we have had a part in your expansion, and are grateful that you area our lifetime contractor. As you well know, the appearance of your home is very important, When you are able to trust a contractor to not take advantage of you and your home, as so many do, we were able to build a trusting relationship, which helps both parties in the long run. I feel honored that I am able to recommend your company to others. We were pleased with the overall experience with your staff, and company as a whole. They were exceptionally friendly, and we did not feel uneasy to leave them alone at our. They completed the said tasks efficiently, and completed everything from start to finish.We stand strong behind Father and Son Builders because we know they are standing strong behind us, as well as members of our community.</p><p align=\"right\"><strong><em>Weldon<br />Phila. Pa 19143 </em></strong></p></td></tr><tr><td height=\"5\" valign=\"top\" class=\"body_font\" align=\"left\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"26%\"><strong>Worked on :</strong> </td><td width=\"74%\">&nbsp;</td></tr><tr><td align=\"left\"><img src=\"images/4.jpg\" width=\"137\" height=\"103\" class=\"img_border\" /></td><td align=\"left\"><img src=\"images/3.jpg\" width=\"135\" height=\"100\" class=\"img_border\" /></td></tr><tr><td align=\"center\">&nbsp;</td><td>&nbsp;</td></tr></table></td></tr><tr><td height=\"5\" valign=\"top\" class=\"border_top\" align=\"left\">&nbsp;</td></tr>";
	
	arr_obj[1] = "<tr><td height=\"5\" valign=\"top\" class=\"body_font\" align=\"left\"><p><strong><img src=\"images/bryan.jpg\" alt=\"\" width=\"200\" height=\"266\" align=\"left\" class=\"img_border\"  style=\"margin-right:5px;\" />February 12, 2003</strong><br />Father and Son Builders did some work for me. They did an excellent job. They installed windows and vinyl siding. I will be calling them again.</p><p align=\"right\"><strong><em>Edwin<br />Phila. Pa 19138 </em></strong></p></td></tr><tr><td height=\"10\" valign=\"top\" class=\"body_font\" align=\"left\">&nbsp;</td></tr><tr><td height=\"10\" valign=\"top\" class=\"body_font\" align=\"left\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"25%\"><strong>Worked on :</strong></td><td width=\"75%\">&nbsp;</td></tr><tr><td align=\"left\"><img src=\"images/2.jpg\" width=\"137\" height=\"103\" class=\"img_border\" /></td><td align=\"left\"><img src=\"images/6.jpg\" width=\"150\" height=\"103\" class=\"img_border\" /></td></tr><tr><td align=\"center\">&nbsp;</td><td>&nbsp;</td></tr></table></td></tr><tr><td height=\"10\" valign=\"top\" class=\"border_top\" align=\"left\">&nbsp;</td></tr>";

		arr_obj[2] ="<tr><td height=\"5\" valign=\"top\" class=\"body_font\" align=\"left\"><p><strong><img src=\"images/keepers.jpg\" alt=\"\" width=\"200\" height=\"249\" align=\"right\" class=\"img_border\"  style=\"margin-left:5px;\" />February 27, 2003</strong><br />My experience with Father and Son Builders is like being the member of a large family! The care the workers show is like they are doing the job for their own Mom. I&rsquo;ve had 5 projects done my Kitchen, patio, Windows, fence and doors and able to afford the low monthly payments they offered through their financing plans. I would not hesitate to call on them again for my next remodeling need. I would not think of another company when you find one you can trust, you stick with them. I am very satisfied with the staff and workmanship. They say &ldquo;You get what you pay for&rdquo; I fell that&rsquo;s TRUE and I&rsquo;ve gotten my monies worth and much, much more. Calling them is like calling on your family.</p><p align=\"right\"><strong><em>Frances <br />Phila. Pa 19135 </em></strong></p></td></tr><tr><td height=\"10\" valign=\"top\" class=\"body_font\" align=\"left\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"26%\"><strong>Worked on :</strong></td><td width=\"74%\">&nbsp;</td></tr><tr><td align=\"left\"><img src=\"images/7.jpg\" width=\"143\" height=\"95\" class=\"img_border\" /></td><td align=\"left\"><img src=\"images/8.jpg\" width=\"143\" height=\"95\" class=\"img_border\" /></td></tr><tr><td align=\"center\">&nbsp;</td><td>&nbsp;</td></tr></table></td></tr><tr><td height=\"5\" valign=\"top\" class=\"border_top\" align=\"left\">&nbsp;</td></tr>";			  

		arr_obj[3] = "<tr><td height=\"5\" valign=\"top\" class=\"body_font\" align=\"left\"><p><strong><img src=\"images/lamonde.jpg\" alt=\"\" width=\"250\" height=\"169\" align=\"left\" class=\"img_border\"  style=\"margin-right:5px;\" />February 12, 2003</strong><br />Our first experience with Father and Son Builders was installing indoor and outdoor railings and having a partial wall built in our bathroom. The contractor worked expertly on these projects. We were very pleased with the complete work so much so that we had them out for other jobs. We had our bathroom remodeled and received quality workmanship on this project. Not only top quality work, but also top quality materials as well. The workers are friendly and will answer any questions you may have. We plan to use Father and Son Builders for our future contracting needs.<br /><br /><strong>CUSTOMERS TESTIMONIAL&rsquo;S &ndash; CARD </strong><br /><br />Dear employees of Father and Son Builders:<br />Just a note to say &ldquo;thank You&rdquo; for the beautiful work you did on our bathroom. We are so pleased with how it turned out. We received top quality workmanship and attention was given to every detail.<br /><br />The crew that came out to our home was on time, worked very hard and were friendly. I felt bent over backwards for us and we truly appreciate their efforts. We plan to call you again for future remodeling. Thanks again.</p><p align=\"right\"><strong><em>Kenneth &amp; Michele <br />Phila. Pa 19154 </em></strong></p></td></tr><tr><td height=\"10\" valign=\"top\" class=\"body_font\" align=\"left\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"24%\"><strong>Worked on :</strong></td><td width=\"76%\">&nbsp;</td></tr><tr><td align=\"left\"><img src=\"images/4.jpg\" width=\"137\" height=\"103\" class=\"img_border\" /></td><td align=\"left\"><img src=\"images/3.jpg\" width=\"135\" height=\"100\" class=\"img_border\" /></td></tr><tr><td align=\"center\">&nbsp;</td><td>&nbsp;</td></tr></table></td></tr><tr><td height=\"10\" valign=\"top\" class=\"border_top\" align=\"left\">&nbsp;</td></tr>";

	arr_obj[4] = "<tr><td height=\"5\" valign=\"top\" class=\"body_font\" align=\"left\"><p><strong><img src=\"images/lutz.jpg\" alt=\"\" width=\"250\" height=\"369\" align=\"right\" class=\"img_border\"  style=\"margin-left:5px;\" />February 27, 2003</strong><br />My overall experience with Father and Son Builders was a very pleasant one. I found the staff professional and knowledgeable. Above all I am thrilled with my new bathroom. It is just as I pictured it to look.<br />Thanks for all your hard work.</p><p align=\"right\"><strong><em>Fern<br />Pa 19018 </em></strong></p></td></tr><tr><td height=\"10\" valign=\"top\" class=\"body_font\" align=\"left\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"26%\"><strong>Worked on :</strong></td><td width=\"74%\">&nbsp;</td></tr><tr><td align=\"left\"><img src=\"images/4.jpg\" width=\"137\" height=\"100\" class=\"img_border\" /></td><td align=\"left\"><img src=\"images/3.jpg\" width=\"135\" height=\"100\" class=\"img_border\" /></td></tr><tr><td align=\"center\">&nbsp;</td><td>&nbsp;</td></tr></table></td></tr><tr><td height=\"10\" valign=\"top\" class=\"border_top\" align=\"left\">&nbsp;</td></tr>";					  
	arr_obj[5] = "<tr><td height=\"5\" valign=\"top\" class=\"body_font\" align=\"left\"><p><strong>February 12, 2003</strong><br />My overall experience with Father and Son Builders has been outstanding, your sales representative   Rick was always punctual, professional and knowledgeable. The project manager Tom was also professional and made some terrific suggestions for the finishing of my basement. Edna and her office staff did an excellent job on coordinating the workmen and following up with customer satisfaction. They made me fell that my project was everyone&rsquo;s top priority as for the men who were assigned to my project they were neat and friendly white completing my new basement in a timely manner. My satisfaction is 100%. I have recommended your company to several of my friends and will continue to do so! Thank you for doing such a wonderful job on my basement. You turned a cement basement into an area that the entire family can relax, entertain and enjoy.</p><p align=\"right\"><strong><em>Anna<br />Phila. Pa 19130 </em></strong></p></td></tr><tr><td height=\"10\" valign=\"top\" class=\"body_font\" align=\"left\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"25%\"><strong>Worked on :</strong></td><td width=\"75%\">&nbsp;</td></tr><tr><td align=\"left\"><img src=\"images/3.jpg\" width=\"137\" height=\"103\" class=\"img_border\" /></td><td align=\"left\"><img src=\"images/5.jpg\" width=\"135\" height=\"100\" class=\"img_border\" /></td></tr><tr><td align=\"center\">&nbsp;</td><td>&nbsp;</td></tr></table></td></tr>";				  
	
 
	var arr2str = arr_obj.toString();  //Converting the String content to String
	
	//if(arr2str.search(searchterm))
		//document.write(arr2str.search(searchterm));  //Search for the Content in the arr2str
	
	postcode1 = "190";
	postcode2 = "191";

	var serverResponse = "";
	
	if(searchterm.substr(0,3)==postcode1)
	{			
		//alert(postcode1+searchterm.substr(0,3));
		var serverResponse = arr_obj[4];
		document.getElementById("searchcontent").innerHTML = serverResponse;
		document.getElementById('searchcontent').style.display = "";	
		document.getElementById('defaultcontent').style.display = "none";	
	}
	else if(searchterm.substr(0,3)==postcode2)
	{
		//alert(postcode2+searchterm.substr(0,3));
		var serverResponse = arr_obj[0]+arr_obj[1]+arr_obj[2]+arr_obj[3]+arr_obj[5];
		document.getElementById("searchcontent").innerHTML = serverResponse;
		document.getElementById('searchcontent').style.display = "";	
		document.getElementById('defaultcontent').style.display = "none";
	}
	else
	{
		//alert('entering');
		alert('Please search by zip code');		
		document.getElementById('searchcontent').style.display = "none";	
		document.getElementById('defaultcontent').style.display = "";
	}		
}
