is.NS=(document.layers || (document.getElementById && !document.all)) ? true : false;

var sehirHTMLSelect='';
var sehirHTMLInput='<input name="contactForm:txtCity" type= "text" id="contactForm_txtCity" />';
	
function sehirle() {
	if (document.getElementById('tdCity')) sehirHTMLSelect=document.getElementById('tdCity').innerHTML;
}
	
function sehirDegistir(countryID) {
	if (sehirHTMLSelect=='' || !document.getElementById('tdCity')) {
		return false;
	} else {
		
		if (countryID=="Türkiye") {
			document.getElementById('tdCity').innerHTML=sehirHTMLSelect;
		} else {
			document.getElementById('tdCity').innerHTML=sehirHTMLInput;	
		}
	}
}
                

function onlyNumber(e) {
var keyCode = (is.NS) ? e.which : e.keyCode;
//alert(keyCode);
	if ((keyCode<48 || keyCode>57)&&keyCode!=8&&keyCode!=0){
	return false;}
	}

function onlyLetter(e) {
	var keyCode = (is.NS) ? e.which : e.keyCode;
	if (keyCode > 47 && keyCode<58){
	return false;}
}

function onlyEmail(e) {
	var InvalidChars=" !#/*{[()]},;^><\\?+:`|";
	
	kCode=InvalidChars.charAt(5);
	
	var keyCode = (is.NS) ? e.which : e.keyCode;
	
	if (keyCode>127 || keyCode<40) {
		return false;
	}
	
	for (i=0;i<=InvalidChars.length-1;i++) {
		if (keyCode==InvalidChars.charCodeAt(i)) {
			return false;
		}
	}
	
	return true;
	
}

	
//Auto Tab formdaki 1 sonraki elemana kaydırır.
function autoTab(input,len, e) {
        var keyCode = (is.NS) ? e.which : e.keyCode; 
        var filter = (is.NS) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
        if(input.value.length >= len && !containsElement(filter,keyCode)) {
                input.value = input.value.slice(0, len);
                input.form[(getIndex(input)+1) % input.form.length].focus();
        }




function containsElement(arr, ele) {
                var found = false, index = 0;
                while(!found && index < arr.length)
                        if(arr[index] == ele)
                                found = true;
                        else
                                index++;
         



               return found;
        }




function getIndex(input) {
                var index = -1; 
                var i = 0;
                var found = false;

                while (i < input.form.length && index == -1) {

                        if (input.form[i] == input) {
                        index = i;
                        }
                        else {
                        i++;
                        }
                
                return index;
                }
       

        return true;
}

/***************************/

function ChkEMail(TmpStr) 
{
	if (TmpStr=="")
	{
		return true;
	}
	else
	{
		var i, atPos, atPos2, InvalidChars=" üÜğĞışŞİçÇöÖ!#/*{[()]}";

		for (i=0; i<InvalidChars.length; i++)
			if (TmpStr.indexOf(InvalidChars.charAt(i)) != -1) {
				return false;
			}
		atPos = TmpStr.indexOf("@");
		atPos1 = TmpStr.indexOf(".");
		atPos2 = TmpStr.indexOf("@", atPos+1);
		if ((atPos < 1) || (atPos1 < 1) || (atPos2 != -1)) {
			return false;
		}
	}
}


function kontrol()
{
	obj=document.forms['Form1'];

	if (!checkLength(obj['contactForm_txtName'],'Name',1)) {
		return false;
	}
	
	if (!checkLength(obj['contactForm_txtSurname'],'Surname',1)) {
		return false;
	}
	
	if (obj['contactForm_ddlCountry'].selectedIndex<2) {
		alert('Please fill in the \"Country\" field.');
		return false;
	}
	
	if (obj['contactForm_ddlCountry'].options[obj['contactForm_ddlCountry'].selectedIndex].value!="216" && obj['contactForm_txtCity'].value.length <1) {
		alert('Please fill in the \"City\" field.');
		return false;
	}
	
	if (obj['contactForm_ddlCountry'].options[obj['contactForm_ddlCountry'].selectedIndex].value=="216" && !obj['contactForm_ddlCity']) {
		sehirDegistir(216);
		alert('Please fill in the \"City\" field.');
		return false;
	}
	
	if (obj['contactForm_ddlCountry'].options[obj['contactForm_ddlCountry'].selectedIndex].value=="216" && obj['contactForm_ddlCity'].selectedIndex<2) {
		alert('Please fill in the \"City\" field.');
		return false;
	}
	
	if (!checkLength(obj['contactForm_txtTelephone'],'Telephone',1)) {
		return false;
	}
	
	if (!checkLength(obj['contactForm_txtEmail'],'E-mail Address',1)) {
		return false;
	}
	
	if (!checkEmail(obj['contactForm_txtEmail'].value)) {
		return false;
	}
	if (!checkLength(obj['contactForm_txtComments'],'Comments / Requests',1)) {
		return false;
	}
	
	
	return true;
}

function checkLength(field,fname,minlength)
{
	if (field.value.length<minlength)
	{
		alert("Please fill in the \""+ fname +"\" field.");
		return (false);
	}
	return (true);
}

/******************************************************************************************************/

function checkEmail(e)
{

  if(e=="")
  {
		alert("Please fill in the \"Email\" field.");
		return false;
  }

  var i =  e.indexOf("@");
  
   if (i<0) 
   	{
		alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false;
	}
	else if (i==0)
	{
		alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false;
	}
	
   var mailbox = e.substring(0,i);
   var domain = e.substring(i+1);
   
   if (domain.indexOf("@")>=0) 
   	{
		alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false;
	}

   alphaSpecial = /[^A-Za-z0-9_\-.]+/;
   alphafront = /^[^A-Za-z0-9]/;
   alphalast = /[^A-Za-z0-9]+$/;

  
	if(alphafront.exec(mailbox)!=null)
	{
	    alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false
	}
	if(alphaSpecial.exec(mailbox)!=null)
	{
		alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false;
	}
	if(alphalast.exec(mailbox)!=null)
	{
	    alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false
	}

	if(alphafront.exec(domain)!=null)
	{
	    alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false
	}
	if(alphaSpecial.exec(domain)!=null)
	{
		alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false;
	}
	if(alphalast.exec(domain)!=null)
	{
	    alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false
	}
   i = domain.lastIndexOf(".");
   if (i<0) 
   	{
		alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false;
	}
	if(!lookup(domain.substring(i+1)))
	{
		alert('Your "E-Mail" address seems to contain an error. Please check and try again.');
		return false;
	}

   alpha = /[_\-.]+/;
   z=mailbox.match(alpha);
	if(z!=null)
		if((String(z).length)>1) return false;
   return true;
}

function lookup(country) {   
    var A = new Array("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", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cs", "cu", "cv", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "er", "es", "et", "fi", "fj", "fk", "fm", "fo", "fr", "fx", "ga", "gb", "gd", "ge", "gf", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gs", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", "hu", "id", "ie", "il", "in", "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", "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", "nt", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "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", "zr", "zw", "com", "edu", "gov", "int", "mil", "net", "org", "arpa", "nato", "tv", "info", "us", "biz", "ws", "cc");
    
    for(i=0; i<A.length; i++)     {         
	    if (country == A[i]) {
	    return true;
	    }
    }     

return false; }
}