function trim(str)
{
    if(typeof str != 'string')
        return null;

    if (str == '')
           return '';

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function DropDownValidation(source,args)
{
    if(args.Value == "None")
    {        
        args.IsValid = false;
    }
    else
    {
        args.IsValid = true;
    }
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function changeUrl()
{
	var url = document.getElementById('<%= this.ClientID %>_txtUrlToRedirect').value;
	alert('url = ' + url);

	window.open(url);
}

function IsEmailValid(emailAddress)
{
    if(emailAddress == "" || emailAddress.length <= 0)
	{
		return false;
	}
	emailAddress = emailAddress.toLowerCase();

	var regexString = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	//var regExp = new Regex(regexString);
	if (!regexString.test(emailAddress)) {
	    return false;
	}
	
	return true;
}

String.prototype.count = function(match) {
var res = this.match(new RegExp(match,"g"));
if (res==null) { return 0; }
return res.length;
}

function IsInternationalPhoneValid(phoneNumber)
{
//	alert(phoneNumber.count("[0-9]"));

	if(phoneNumber == "" || phoneNumber.length <= 0)
	{
			return false;
	}
	
	if(phoneNumber.count("[0-9]") > 15)
	{
		return false;
	}
	
	return true;
}

function IsEmailDomainValid(emailAddress)
{
    if(emailAddress == "" || emailAddress.length <= 0)
	{
		return false;
	}
	emailAddress = emailAddress.toLowerCase();

	// If no valid domain name was specified
	var startDomainIndex = emailAddress.lastIndexOf("@") + 1;
	if ((startDomainIndex <= 0) || (emailAddress.Length <= startDomainIndex))
	{
	    return false;
	}

	// Get domain part
	var domainName = emailAddress.substring(startDomainIndex);
	if(domainName == "" || domainName.length <= 0)
	{
	    return false;
	}

    var freeDomainList = "111mail.com,123iran.com,1-usa.com,2die4.com,37.com,420email.com,4degreez.com,4-music-today.com,5005.lv,a.org.ua,abha.cc,accountant.com,actingbiz.com,adexec.com,africamail.com,agadir.cc,ahsa.ws,ajman.cc,ajman.us,ajman.ws,albaha.cc,alex4all.com,alexandria.cc,algerie.cc,allergist.com,allhiphop.com,alriyadh.cc,alumnidirector.com,amman.cc,anatomicrock.com,animeone.com,anjungcafe.com,aqaba.cc,arar.ws,archaeologist.com,arcticmail.com,artlover.com,asia.com,asiancutes.com,aswan.cc,a-teens.net,ausi.com,australiamail.com,autoindia.com,autopm.com,baalbeck.cc,bahraini.cc,banha.cc,barriolife.com,b-boy.com,beautifulboy.com,berlin.com,bgay.com,bicycledata.com,bicycling.com,bigheavyworld.com,bigmailbox.net,bikerheaven.net,bikerider.com,bikermail.com,billssite.com,bizerte.cc,bk.ru,blackandchristian.com,blackcity.net,blackvault.com,blida.info,bmx.lv,bmxtrix.com,boarderzone.com,boatnerd.com,bolbox.com,bongmail.com,bowl.com,buraydah.cc,butch-femme.org,byke.com,calle22.com,cameroon.cc,cannabismail.com,catlover.com,catlovers.com,certifiedbitches.com,championboxing.com,chatway.com,cheerful.com,chemist.com,chillymail.com,classprod.com,classycouples.com,clerk.com,cliffhanger.com,columnist.com,comic.com,company.org.ua,congiu.net,consultant.com,coolmail.ru,coolshit.com,corpusmail.com,counsellor.com,cutey.com,cyberunlimited.org,cycledata.com,darkfear.com,darkforces.com,deliveryman.com,dhahran.cc,dhofar.cc,dino.lv,diplomats.com,dirtythird.com,djibouti.cc,doctor.com,doglover.com,dominican.cc,dopefiends.com,dr.com,draac.com,drakmail.net,dr-dre.com,dreamstop.com,dublin.com,earthling.net,earthling.net,eclub.lv,egypt.net,e-mail.am,email.com,e-mail.ru,emailfast.com,emails.ru,e-mails.ru,eminemfans .com,envirocitizen.com,eritrea.cc,eritrea.cc,escapeartist.com,europe.com,execs.com,ezsweeps.com,falasteen.cc,famous.as,farts.com,feelingnaughty.com,financier.com,firemyst.com,fit.lv,freeonline.com,fromru.com,front.ru,fudge.com,fujairah.cc,fujairah.us,fujairah.ws,funkytimes.com,gabes.cc,gafsa.cc,gala.net,gamerssolution.com,gardener.com,gawab.com,gazabo.net,geologist.com,giza.cc,glittergrrrls.com,goatrance.com,goddess.com,gohip.com,goldenmail.ru,goldmail.ru,gospelcity.com,gothicgirl.com,gotomy.com,grapemail.net,graphic-designer.com,greatautos.org,guinea.cc,guinea.cc,guy.com,hacker.am,hairdresser.net,haitisurf.com,hamra.cc,happyhippo.com,hasakah.com,hateinthebox.com,hebron.tv,hip hopmail.com,homs.cc,hotbox.ru,hot-shot.com,houseofhorrors.com,hugkiss.com,hullnumber.com,human.lv,ibra.cc,idunno4recipes.com,ihatenetscape.com,iname.com,inbox.ru,inorbit.com,insurer.com,intimatefire.com,iphon.biz,irbid.ws,irow.com,ismailia.cc,jadida.cc,jadida.org,japan.com,jazzemail.com,jerash.cc,jizan.cc,jouf.cc,journalist.com,juanitabynum.com,kairouan.cc,kanoodle.com,karak.cc,khaimah.cc,khartoum.cc,khobar.cc,kickboxing.com,kidrock.com,kinkyemail.com,kool-things.com,krovatka.net,kuwaiti.tv,kyrgyzstan.cc,land.ru,latakia.cc,latchess.com,latinabarbie.com,latinogreeks.com,lawyer.com,lebanese.cc,leesville.com,legislator.com,list.ru,lobbyist.com,london.com,loveable.com,loveemail.com,loveis.lv,lovers-mail.com,lowrider.com,lubnan.cc,lubnan.ws,lucky7lotto.net,lv-inter.net,mad.scientist.com,madeniggaz.net,madinah.cc,madrid.com,maghreb.cc,mail.com,mail.ru,mail15.com,mail333.com,mailbomb.com,manama.cc,mansoura.tv,marillion.net,marrakesh.cc,mascara.ws,megarave.com,meknes.cc,mesra.net,mindless.com,minister.com,mofa.com,moscowmail.com,motley.com,munich.com,muscat.tv,muscat.ws,music.com,musician.net,musician.org,musicsites.com,myself.com,nabeul.cc,nabeul.info,nablus.cc,nador.cc,najaf.cc,narod.ru,netbroadcaster.com,netfingers.com,net-surf.com,nettaxi.com,newmail.ru,ni cedriveway.com,nightmail.ru,nm.ru,nocharge.com,nycmail.com,omani.ws,omdurman.cc,operationivy.com,optician.com,oran.cc,oued.info,oued.org,oujda.biz,oujda.cc,paidoffers.net,pakistani.ws,palmyra.cc,palmyra.ws,pcbee.com,pediatrician.com,persian.com,petrofind.com,phunkybitches.com,pikaguam.com,pinkcity.net,pisem.net,pitbullmail.com,planetsmeg.com,playful.com,pochta.ru,pochtamt.ru,poetic.com,pookmail.com,poop.com,poormail.com,pop3.ru,popstar.com,portsaid.cc,post.com,potsmokersnet.com,presidency.com,priest.com,primetap.com,programmer.net,project420.com,prolife.net,publicist.com,puertoricowow.com,puppetweb.com,qassem.cc,quds.cc,rabat.cc,rafah.cc,ramallah.cc,rambler.ru,rapstar.com,rapworld.com,rastamall.com,ratedx.net,ravermail.com,rbcmail.ru,realtyagent.com,registerednurses.com,relapsecult.com,remixer.com,repairman.com,representative.com,rescueteam.com,rockeros.com,romance106fm.com,rome.com,sa veourplanet.org,safat.biz,safat.info,safat.us,safat.ws,saintly.com,salalah.cc,salmiya.biz,samerica.com,sanaa.cc,sanfranmail.com,scientist.com,seductive.com,seeb.cc,sexriga.lv,sfax.ws,sharm.cc,sinai.cc,singalongcenter.com,singapore.com,siria.cc,sketchyfriends.com,slayerized.com,smartstocks.com,smtp.ru,sociologist.com,sok.lv,soon.com,soulja-beatz.org,sousse.cc,spam.lv,specialoperations.com,speedymail.net,spells.com,streetracing.com,subspacemail.com,sudanese.cc,suez.cc,sugarray.com,superbikeclub.com,superintendents.net,supermail.ru,surfguiden.com,sweetwishes.com,tabouk.cc,tajikistan.cc,tangiers.cc,tanta.cc,tattoodesign.com,tayef.cc,teamster.net,techie.com,technologist.com,teenchatnow.com,tetouan.cc,the5thquarter.com,theblackmarket.com,timor.cc,tokyo.com,tombstone.ws,troamail.org,tunisian.cc,tut.by,tx.am,u2tours.com,ua.fm,uaix.info,umpire.com,urdun.cc,usa.com,vipmail.ru,vitalogy.org,whatisthis.com,whoever.com,winning.com,witty.com,wrestlezone.com,writeme.com,yanbo.cc,yandex.ru,yemeni.cc,yogaelements.com,yours.com,yunus.cc,zabor.lv,zagazig.cc,zambia.cc,zarqa.cc,zerogravityclub.com,bezeqint.net,nana10.co.il,talktalk.net,ymail.com, gmail1.com,gmail2.com,gmail3.com,gmail4.com,gmail5.com,gmail6.com,wecmail.cz.cc";

    var temporaryMailDomainList = "10minutemail.com,anonymbox.com,dispostable.com,dodgeit.com,e4ward.com,gishpuppy.com,guerrillamail.com,haltospam.com,jetable.org,kasmail.com,mailexpire.com,maileater.com,mailinator.com,mailnull.com,meltmail.com,mintemail.com,mytrashmail.com,nospamfor.us,pookmail.com,shortmail.net,skeefmail.com,slopsbox.com,sneakemail.com,soodonims.com,spamjackal.net,spam.la,spam.su,spambob.com,spambox.us,spamfree24.org,spamgourmet.com,stealth-mode.net,stop-my-spam.com,tempail.com,tempemail.net,willhackforfood.biz,sogetthis.com";

    if (freeDomainList.indexOf(domainName)!=-1)
    {
        return false;
    }

    if (temporaryMailDomainList.indexOf(domainName)!=-1)
    {
        return false;
    }

    var multiCountryDomainList = "hotmail,live,yahoo,gmail,msn"; 
    
    var domainNameWithoutExtention = domainName.substring(0,domainName.lastIndexOf("."));

    if (multiCountryDomainList.indexOf(domainNameWithoutExtention)!=-1)
    {
        return false;
    }

	return true;
 } 
 
var phoneDictionary = {};
phoneDictionary.None = "";
phoneDictionary.Afghanistan	=	"+93";
phoneDictionary.Albania	=	"+355";
phoneDictionary.Algeria	=	"+213";
phoneDictionary.Andorra	=	"+376";
phoneDictionary.Angola	=	"+244";
phoneDictionary["Antigua and Barbuda"]	=	"+1";
phoneDictionary.Argentina	=	"+54";
phoneDictionary.Armenia	=	"+374";
phoneDictionary.Australia	=	"+61";
phoneDictionary.Austria	=	"+43";
phoneDictionary.Azerbaijan	=	"+994";
phoneDictionary.Bahamas	=	"+1";
phoneDictionary.Bahrain	=	"+973";
phoneDictionary.Bangladesh	=	"+880";
phoneDictionary.Barbados	=	"+1";
phoneDictionary.Belarus	=	"+375";
phoneDictionary.Belgium	=	"+32";
phoneDictionary.Belize	=	"+501";
phoneDictionary.Benin	=	"+229";
phoneDictionary.Bermuda	=	"+1";
phoneDictionary.Bhutan	=	"+975";
phoneDictionary.Bolivia	=	"+591";
phoneDictionary["Bosnia and Herzegovina"]	=	"+387";
phoneDictionary.Botswana	=	"+267";
phoneDictionary.Brazil	=	"+55";
phoneDictionary["Brunei Darussalam"]	=	"+673";
phoneDictionary.Bulgaria	=	"+359";
phoneDictionary["Burkina Faso"]	=	"+226";
phoneDictionary.Burundi	=	"+257";
phoneDictionary.Cambodia	=	"+855";
phoneDictionary.Cameroon	=	"+237";
phoneDictionary.Canada	=	"+1";
phoneDictionary["Cape Verde"]	=	"+238";
phoneDictionary["Central African Republic"]	=	"+236";
phoneDictionary.Chad	=	"+235";
phoneDictionary.Chile	=	"+56";
phoneDictionary.China	=	"+86";
phoneDictionary.Colombia	=	"+57";
phoneDictionary.Comoros	=	"+269";
phoneDictionary.Congo	=	"+243";
phoneDictionary["Costa Rica"]	=	"+506";
phoneDictionary["Cote d'Ivoire"]	=	"+225";
phoneDictionary.Croatia	=	"+385";
phoneDictionary.Cuba	=	"+53";
phoneDictionary.Cyprus	=	"+357";
phoneDictionary["Czech Republic"]	=	"+420";
phoneDictionary.Denmark	=	"+45";
phoneDictionary.Djibouti	=	"+253";
phoneDictionary.Dominica	=	"+1";
phoneDictionary["Dominican Republic"]	=	"+1";
phoneDictionary.Ecuador	=	"+593";
phoneDictionary.Egypt	=	"+20";
phoneDictionary["El Salvador"]	=	"+503";
phoneDictionary["Equatorial Guinea"]	=	"+240";
phoneDictionary.Eritrea	=	"+291";
phoneDictionary.Estonia	=	"+372";
phoneDictionary.Ethiopia	=	"+251";
phoneDictionary.Fiji	=	"+679";
phoneDictionary.Finland	=	"+358";
phoneDictionary.France	=	"+33";
phoneDictionary.Gabon	=	"+241";
phoneDictionary.Georgia	=	"+995";
phoneDictionary.Germany	=	"+49";
phoneDictionary.Ghana	=	"+233";
phoneDictionary.Gibraltar	=	"+350";
phoneDictionary.Greece	=	"+30";
phoneDictionary.Grenada	=	"+1";
phoneDictionary.Guam	=	"+1";
phoneDictionary.Guatemala	=	"+502";
phoneDictionary.Guinea	=	"+224";
phoneDictionary["Guinea-Bissau"]	=	"+245";
phoneDictionary.Guyana	=	"+592";
phoneDictionary.Haiti	=	"+509";
phoneDictionary.Honduras	=	"+504";
phoneDictionary["Hong Kong"]	=	"+852";
phoneDictionary.Hungary	=	"+36";
phoneDictionary.Iceland	=	"+354";
phoneDictionary.India 	=	"+91";
phoneDictionary.Indonesia	=	"+62";
phoneDictionary.Iraq	=	"+964";
phoneDictionary.Ireland	=	"+353";
phoneDictionary.Israel	=	"+972";
phoneDictionary.Italy	=	"+39";
phoneDictionary.Jamaica	=	"+1";
phoneDictionary.Japan	=	"+81";
phoneDictionary.Jordan	=	"+962";
phoneDictionary.Kazakhstan	=	"+7";
phoneDictionary.Kenya	=	"+254";
phoneDictionary.Kiribati	=	"+686";
phoneDictionary["Korea, Republic of"]	=	"+82";
phoneDictionary.Kuwait	=	"+965";
phoneDictionary.Kyrgyzstan	=	"+996";
phoneDictionary["Lao People's Democratic Republic"]	=	"+856";
phoneDictionary.Latvia	=	"+371";
phoneDictionary.Lebanon	=	"+961";
phoneDictionary.Lesotho	=	"+266";
phoneDictionary.Liberia	=	"+231";
phoneDictionary["Libyan Arab Jamahiriya"] =	"+218";
phoneDictionary.Liechtenstein	=	"+423";
phoneDictionary.Lithuania	=	"+370";
phoneDictionary.Luxembourg	=	"+352";
phoneDictionary.Macau	=	"+853";
phoneDictionary["Macedonia, The Former Yugoslav Republic"]	=	"+389";
phoneDictionary.Madagascar	=	"+261";
phoneDictionary.Malawi	=	"+265";
phoneDictionary.Malaysia	=	"+60";
phoneDictionary.Maldives	=	"+960";
phoneDictionary.Mali	=	"+223";
phoneDictionary.Malta	=	"+356";
phoneDictionary["Marshall Islands"]	=	"+692";
phoneDictionary.Mauritania	=	"+222";
phoneDictionary.Mauritius	=	"+230";
phoneDictionary.Mexico	=	"+52";
phoneDictionary["Micronesia (Federated States of)"]	=	"+691";
phoneDictionary["Moldova, Republic of"]	=	"+373";
phoneDictionary.Monaco	=	"+377";
phoneDictionary.Mongolia	=	"+976";
phoneDictionary.Morocco	=	"+212";
phoneDictionary.Mozambique	=	"+258";
phoneDictionary.Namibia	=	"+264";
phoneDictionary.Nauru	=	"+674";
phoneDictionary.Nepal	=	"+977";
phoneDictionary.Netherlands	=	"+31";
phoneDictionary["New Zealand"]	=	"+64";
phoneDictionary.Nicaragua	=	"+505";
phoneDictionary.Niger	=	"+227";
phoneDictionary.Nigeria	=	"+234";
phoneDictionary.Norway	=	"+47";
phoneDictionary.Oman	=	"+968";
phoneDictionary.Pakistan	=	"+92";
phoneDictionary.Palau	=	"+680";
phoneDictionary.Panama	=	"+507";
phoneDictionary["Papua New Guinea"]	=	"+675";
phoneDictionary.Paraguay	=	"+595";
phoneDictionary.Peru	=	"+51";
phoneDictionary.Philippines	=	"+63";
phoneDictionary.Poland	=	"+48";
phoneDictionary.Portugal	=	"+351";
phoneDictionary["Puerto Rico"]	=	"+1";
phoneDictionary.Qatar	=	"+974";
phoneDictionary.Romania	=	"+40";
phoneDictionary["Russian Federation"]	=	"+7";
phoneDictionary.Rwanda	=	"+250";
phoneDictionary["Saint Lucia"]	=	"+1";
phoneDictionary["San Marino"]	=	"+378";
phoneDictionary["Saudi Arabia"]	=	"+966";
phoneDictionary.Senegal	=	"+221";
phoneDictionary.Seychelles	=	"+248";
phoneDictionary["Sierra Leone"]	=	"+232";
phoneDictionary.Singapore	=	"+65";
phoneDictionary.Slovakia	=	"+421";
phoneDictionary.Slovenia	=	"+386";
phoneDictionary["Solomon Islands"]	=	"+677";
phoneDictionary.Somalia	=	"+252";
phoneDictionary["South Africa"]	=	"+27";
phoneDictionary.Spain	=	"+34";
phoneDictionary["Sri Lanka"]	=	"+94";
phoneDictionary.Suriname	=	"+597";
phoneDictionary.Swaziland	=	"+268";
phoneDictionary.Sweden	=	"+46";
phoneDictionary.Switzerland	=	"+41";
phoneDictionary.Taiwan	=	"+886";
phoneDictionary.Tajikistan	=	"+992";
phoneDictionary["Tanzania, United Republic of"]	=	"+255";
phoneDictionary.Thailand	=	"+66";
phoneDictionary.Togo	=	"+228";
phoneDictionary.Tonga	=	"+676";
phoneDictionary["Trinidad and Tobago"]	=	"+1";
phoneDictionary.Tunisia	=	"+216";
phoneDictionary.Turkey	=	"+90";
phoneDictionary.Turkmenistan	=	"+993";
phoneDictionary.Tuvalu	=	"+688";
phoneDictionary.Uganda	=	"+256";
phoneDictionary.Ukraine	=	"+380";
phoneDictionary["United Arab Emirates"]	=	"+971";
phoneDictionary["United Kingdom"]	=	"+44";
phoneDictionary["United States"]	=	"+1";
phoneDictionary.Uruguay	=	"+598";
phoneDictionary.Uzbekistan	=	"+998";
phoneDictionary.Vanuatu	=	"+678";
phoneDictionary.Venezuela	=	"+58";
phoneDictionary.Vietnam	=	"+84";
phoneDictionary.Yemen	=	"+967";
phoneDictionary.Zambia	=	"+260";
phoneDictionary.Zimbabwe	=	"+263";

var lastPreffix = ""; 
	
function SetPhonePreffixByCountry(countryDropDownList, phoneTextBoxControl)
{
	SetPhonePreffixByCountry(countryDropDownList, phoneTextBoxControl, true);
}
	
function SetPhonePreffixByCountry(countryDropDownList, phoneTextBoxControl, isSetFocus)
{
	if(countryDropDownList == "")
	{
		lastPreffix = "";
		return;
	}	
	
	if (phoneTextBoxControl.value == "" || phoneTextBoxControl.value == lastPreffix)
	{
		phoneTextBoxControl.value = "";
		
		if( phoneDictionary[countryDropDownList.value] != "" && 
			phoneDictionary[countryDropDownList.value] != 'undefined' )
		{
			// to move focus to the end of the phone preffix
			if(isSetFocus)
			{
				phoneTextBoxControl.focus();
			}
			phoneTextBoxControl.value = phoneDictionary[countryDropDownList.value] + "-";
			
			lastPreffix = phoneTextBoxControl.value;
			
			if(isSetFocus)
			{
				phoneTextBoxControl.focus();
			}
		}
	}
	
	if(phoneTextBoxControl.value != "")
	{				
		return;		
	}
}

function IsPhoneNumberProvided(countryDropDownList, phoneTextBoxControl)
{	
	if(countryDropDownList == "" || 
	   phoneTextBoxControl == "" ||
	   phoneDictionary[countryDropDownList.value] == "" ||
	   phoneDictionary[countryDropDownList.value] == 'undefined')
	   {
			return false;
	   }
   
	if(trim(phoneTextBoxControl.value) == trim(phoneDictionary[countryDropDownList.value]) ||
	   trim(phoneTextBoxControl.value) == trim(phoneDictionary[countryDropDownList.value] + "-"))
	{
		return false;
	}	
	
	return true;
}
