<!--
//********************************************************************
// VERSION	1.0
// CREATED	9/6/2009
// AUTHOR	jaideep(jd@tcc247.com)
// SUMMARY	This javascript function will validate the field of various forms
//********************************************************************


//Strip whitespace from the beginning and end of a string
//Input : a string
function affliatetype()
{
	alert ("You have login as User Please logout then try again");
	}

function trim(str)
{
    return str.replace(/^\s+|\s+$/g,'');
}

/*
Check if a string is in valid email format. 
Returns true if valid, false otherwise.
*/

function checkDomain(nname)
{
var arr = new Array(
'.com','.net','.org','.biz','.coop','.info','.museum','.name',
'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
'.wf','.ye','.yt','.yu','.za','.zm','.zw');

var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 // alert("Your domain extension "+ext+" is not correct");
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 // alert("Domain name should not begin are end with '-'");
			      return false;
		 	 }
		  }
		else	{
		  	 // alert("Your domain name should not have special characters");
			 return false;
		  }
		}
	}
}
else
{
 // alert("Your Domain name is too short/long");
 return false;
}	

return true;
}


function isEmail(str)
{
	// Should not beging with a '.' or '@'
	if(str.charAt(0)=='@' || str.charAt(0) == '.')
	{	
		return false;
	}

    var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
    return regex.test(str);
}

function isNumber(TheNumber) {
	var valid = 1
	var GoodChars = "-+0123456789"
	var i = 0
	if (TheNumber=="") {
		// Return false if number is empty
		valid = 0
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
			valid = 0
		} // End if statement
	} // End for loop
	return valid
}	

function validateMultipleSelect(listObject) {

	// "listObject" is the object input array for the select 
	// list, referenced in the function call as "this.name", where
	// "name" is the name of the select list.
	// "numToSelect" is the number of items you allow to be selected.

	var j = 0;

	for (var i = 0; i < listObject.length; i++) {
		if (listObject.options[i].selected) {
			j++;
		}
	}
	
	if (j < 1)
	{
		return (false);
	} else {
		return (true);
	}
}

/////////////////////////////////////////  jai affiliate validation started ///////////////////////





/////////////////////////////////////////  jai affiliate validation end ///////////////////////


function createAccountForm()
{
	
var email_create;

	with(window.document.create_account_form)
    {
		cemail = email_create;
	}
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
}



function contactForm()
{
	
var id_contact, from, message, code;

	with(window.document.contact_form)
    {
		cid_contact = id_contact;
		cemail = from;
		cmessage = message;
		ccode = code;
	}
	
	if(cid_contact.value == "")
    {
        alert('Please select subject');
        cid_contact.focus();
        return false;
    }
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	if(trim(cmessage.value) == '')
    {
        alert('Please write message.');
        cmessage.focus();
        return false;
    }
	
	if(trim(ccode.value) == '')
    {
        alert('Please enter security code.');
        ccode.focus();
        return false;
    }
	
	if(ccode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        ccode.focus();
        return false;
    }
}

function contactForm1()
{
	
var name,  from, message, code;

	with(window.document.contact_form)
    {
		name=name;
		 
		cemail = from;
		 
		cmessage = message;
		ccode = code;
	}
	if(name.value == "")
    {
        alert('Please select name');
        name.focus();
        return false;
    }
	
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	if(trim(cmessage.value) == '')
    {
        alert('Please write message.');
        cmessage.focus();
        return false;
    }
	
	if(trim(ccode.value) == '')
    {
        alert('Please enter security code.');
        ccode.focus();
        return false;
    }
	
	if(ccode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        ccode.focus();
        return false;
    }
}




function testimonialForm()
{
	
var name, description, logincode;

	with(window.document.testimonial)
    {
		cname = name;
		cdescription = description;
		clogincode = logincode;
	}
	
	if(trim(cname.value) == '')
    {
        alert('Please enter name.');
        cname.focus();
        return false;
    }
	
	if(trim(cdescription.value) == '')
    {
        alert('Please enter description.');
        cdescription.focus();
        return false;
    }
	
	if(trim(clogincode.value) == '')
    {
        alert('Please enter security code.');
        clogincode.focus();
        return false;
    }
	
	if(clogincode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        clogincode.focus();
        return false;
    }
}

function addURLForm()
{
var urlfilter= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;	
var name, siteurl, urlto, content, logincode;

	with(window.document.addurl)
    {
		cname = name;
		csiteurl = siteurl;
		curlto = urlto;
		cdescription = content;
		clogincode = logincode;
	}
	
	if(trim(cname.value) == '')
    {
        alert('Please enter name.');
        cname.focus();
        return false;
    }
	if(trim(csiteurl.value) == '')
    {
        alert('Please enter siteurl.');
        csiteurl.focus();
        return false;
    }
	if(!urlfilter.test(csiteurl.value))
	{
		alert("Please Enter Website URL in this (http://www.genericdoctor.com) format.");
		csiteurl.focus();
		return false;
		}
	
	
	if(trim(curlto.value) == '')
    {
        alert('Please enter urlto.');
        curlto.focus();
        return false;
    }
	if(!urlfilter.test(curlto.value))
	{
		alert("Please Enter Website URL in this (http://www.genericdoctor.com) format.");
		curlto.focus();
		return false;
		}
	if(trim(cdescription.value) == '')
    {
        alert('Please enter description.');
        cdescription.focus();
        return false;
    }
	
	if(trim(clogincode.value) == '')
    {
        alert('Please enter security code.');
        clogincode.focus();
        return false;
    }
	
	if(clogincode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        clogincode.focus();
        return false;
    }
}


function checkAuthenticateForm()
{
var email, passwd;

	with(window.document.login_form)
    {
		
		cemail = email;
		cpassword = passwd;
		 
	}
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	if(trim(cpassword.value) == '')
    {
        alert('Please enter password');
        cpassword.focus();
        return false;
    }
	
	if(cpassword.value.length<5)
    {
        alert('Password should be greater than 5.');
        cpassword.focus();
        return false;
    }
	
}


function checkRegisterForm()
{
var customer_firstname, customer_lastname,email,passwd,address1, postcode, city,id_state, id_country, phone_mobile,alias;

	with(window.document.account_creation_form)
    {
		ccustomer_firstname = customer_firstname;
		ccustomer_lastname = customer_lastname;
		cemail = email;
		cpasswd=passwd;
		caddress1 = address1;
		cpostcode = postcode;
		ccity = city;
		cid_state=id_state;
		cid_country = id_country;
		cphone_mobile=phone_mobile;
		calias = alias;
	}
	if(trim(ccustomer_firstname.value) == '')
    {
        alert('Please enter first name.');
        ccustomer_firstname.focus();
        return false;
    }
	if(trim(ccustomer_lastname.value) == '')
    {
        alert('Please enter last name.');
        ccustomer_lastname.focus();
        return false;
    }
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	
	if(trim(cpasswd.value) == '')
    {
        alert('Please enter password');
        cpasswd.focus();
        return false;
    }
	
	if(cpasswd.value.length<5)
    {
        alert('Password should be greater than 5.');
        cpasswd.focus();
        return false;
    }
	if(trim(caddress1.value) == '')
    {
        alert('Please enter address.');
        caddress1.focus();
        return false;
    }
	
	if(trim(cpostcode.value) == '')
    {
        alert('Please enter Postcode.');
        cpostcode.focus();
        return false;
    }
	if(cpostcode.value.length>6)
    {
        alert('Postcode maximum charater will not exceed more than 6.');
        cpostcode.focus();
        return false;
    }
	
	/*if(isNaN(cpostcode.value))
    {
        alert('Postcode should be numeric.');
        cpostcode.focus();
        return false;
    }*/
	
	if(trim(ccity.value) == '')
    {
        alert('Please enter city.');
        ccity.focus();
        return false;
    }
	
	if(trim(cid_state.value) == '')
    {
        alert('Please select state.');
        cid_state.focus();
        return false;
    }
	/*if(trim(cid_state.value) == '')
    {
        alert('Please select state.');
        cid_state.focus();
        return false;
    }*/
	
	if(trim(cid_country.value) == '')
    {
        alert('Please enter Postcode.');
        cid_country.focus();
        return false;
    }
	if(cphone_mobile.value == '')
    {
        alert('Please enter Phone number.');
        cphone_mobile.focus();
        return false;
    }
	/*if(isNaN(cphone_mobile.value))
    {
        alert('Contact should be numeric.');
        cphone_mobile.focus();
        return false;
    }*/
	if(trim(calias.value) == '')
    {
        alert('Please enter address title for future.');
        calias.focus();
        return false;
    }
	
	 
	
}






function checknewsForm()
{
var email;

	with(window.document.newsform)
    {
		
		cemail = email;
		
	}
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	
	
}


// forgotn password
function forgotpass()
{
var email, code;

	with(window.document.forgotpassword)
    {
		
		cemail = email;
		ccode  = code;
		
	}
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	if(trim(ccode.value) == '')
    {
        alert('Please enter security code.');
        ccode.focus();
        return false;
    }
	
	if(ccode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        ccode.focus();
        return false;
    }
	
}


function sendtofriendvalidation()
{
var email;

	with(window.document.sendtofriend)
    {
		cname = name;
		cemail = email;
		
	}
	
	if(trim(cname.value) == '')
    {
        alert('Please enter name');
        cname.focus();
        return false;
    }
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	
	
}


function reordercheckbox(){
	var total=""
for(var i=0; i < document.reorderform.countre.value; i++){
if(document.reorderform.id_cart1[i].checked)
total +=document.form1.id_cart1[i].value + "\n"
}
if(total==""){
alert("Please check at least one order")
return false;
}
	}

function checkaccounteditform(){
	if(document.account_creation_form.firstname.value==""){
			alert("Please enter your first name")
			document.account_creation_form.firstname.focus();
        return false;
			}
			if(document.account_creation_form.lastname.value==""){
			alert("Please enter your last name")
			document.account_creation_form.lastname.focus();
        return false;
			}
			if(document.account_creation_form.address1.value==""){
			alert("Please enter your address1")
			document.account_creation_form.address1.focus();
        return false;
			}
			if(document.account_creation_form.city.value==""){
			alert("Please enter your city")
			document.account_creation_form.city.focus();
        return false;
			}
			if(document.account_creation_form.county.value==""){
			alert("Please enter your state")
			document.account_creation_form.county.focus();
        return false;
			}
			if(document.account_creation_form.postcode.value==""){
			alert("Please enter your postcode")
			document.account_creation_form.postcode.focus();
        return false;
			}
			
			if(document.account_creation_form.id_country.value==""){
			alert("Please select country")
			document.account_creation_form.id_country.focus();
        return false;
			}
			if(document.account_creation_form.phone.value==""){
			alert("Please enter phone number")
			document.account_creation_form.phone.focus();
        return false;
			}
			}



//open popup for old site msg

<!--
function toggleDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}


//contact
function contact()
{
var name, from, message, code;

	with(window.document.contact_form)
    {
		cname = name;
		cemail = from;
		cmessage = message;
		ccode = code;
	}
	
	if(cname.value == '')
    {
        alert('Please enter name');
        cname.focus();
        return false;
    }
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	if(trim(cmessage.value) == '')
    {
        alert('Please write message.');
        cmessage.focus();
        return false;
    }
	
	if(trim(ccode.value) == '')
    {
        alert('Please enter security code.');
        ccode.focus();
        return false;
    }
	
	if(ccode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        ccode.focus();
        return false;
    }
}

//order Status

function orderstatus()
{
	var orderfilter = /^[0-9]+$/; 
var order, from, code;

	with(window.document.contact_form)
    {
		corder = order;
		cemail = from;
		ccode  = code
		}
	
	if(corder.value == '')
    {
        alert('Please enter Order Number');
        corder.focus();
        return false;
    }
	if(!orderfilter.test(corder.value)) 
	    {
        alert('Please enter correct Order Number');
        corder.focus();
        return false;
    }
	
	
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	if(trim(ccode.value) == '')
    {
        alert('Please enter security code.');
        ccode.focus();
        return false;
    }
	
	if(ccode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        ccode.focus();
        return false;
    }
}

// medicinessearch
function medicinessearch()
{
	if(document.contact_form.name.value == '')
    {
        alert('Please enter name');
        document.contact_form.name.focus();
        return false;
    }
	
	if(trim(document.contact_form.from.value) == '')
    {
        alert('Please enter email address');
       document.contact_form.from.focus();
        return false;
    }
	if(!isEmail(trim(document.contact_form.from.value)))    {
        alert('Please enter valid email address');
       document.contact_form.from.focus();
        return false;
    }
	if(trim(document.contact_form.productname.value) == '')
    {
        alert('Please write Product Name.');
        document.contact_form.productname.focus();
        return false;
    }
	
	if(trim(document.contact_form.code.value) == '')
    {
        alert('Please enter security code.');
        document.contact_form.code.focus();
        return false;
    }
	
	if(document.contact_form.code.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        document.contact_form.code.focus();
        return false;
    }
}

//customersupport
function customersupport()
{
	var orderfilter = /^[0-9]+$/; 
var name, from, order, message, code;

	with(window.document.contact_form)
    {
		cname = name;
		cemail = from;
		corder = order;
		cmessage = message;
		ccode = code;
	}
	
	if(cname.value == '')
    {
        alert('Please enter name');
        cname.focus();
        return false;
    }
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	if(corder.value == '')
    {
        alert('Please enter order');
        corder.focus();
        return false;
    }
	if(!orderfilter.test(corder.value)) 
	    {
        alert('Please enter correct Order Number');
        corder.focus();
        return false;
    }
	if(trim(cmessage.value) == '')
    {
        alert('Please write query.');
        cmessage.focus();
        return false;
    }
	
	if(trim(ccode.value) == '')
    {
        alert('Please enter security code.');
        ccode.focus();
        return false;
    }
	
	if(ccode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        ccode.focus();
        return false;
    }
}


//quickmessage
function quickmessage()
{
var name, from, message, code;

	with(window.document.contact_form)
    {
		cname = name;
		cemail = from;
		cmessage = message;
		ccode = code;
	}
	
	if(cname.value == '')
    {
        alert('Please enter name');
        cname.focus();
        return false;
    }
	
	if(trim(cemail.value) == '')
    {
        alert('Please enter email address');
        cemail.focus();
        return false;
    }
	if(!isEmail(trim(cemail.value)))    {
        alert('Please enter valid email address');
        cemail.focus();
        return false;
    }
	if(trim(cmessage.value) == '')
    {
        alert('Please write your query.');
        cmessage.focus();
        return false;
    }
	
	if(trim(ccode.value) == '')
    {
        alert('Please enter security code.');
        ccode.focus();
        return false;
    }
	
	if(ccode.value.length!=4)
    {
        alert('Security code length must be 4 character long.');
        ccode.focus();
        return false;
    }
}

function emailblank(){
	document.login_form.email.value=""
	}
function passwdblank(){
	document.login_form.passwd.value=""
	}
	function emailcreateblank(){
	document.create_account_form.email_create.value=""
	}
//-->

