
/******************************************************LOGIN AND VALIDATION JS********************************************************************/
function doSubmit() {
 txt=document.login.userTypeS.options[document.login.userTypeS.selectedIndex].text;
 if(document.login.userTypeS.options[document.login.userTypeS.selectedIndex].value == "none")
{
	document.getElementById("userTypeS").style.background = "#cc0000";

}
	else if (txt.match('Customer')){
	
		var field1 = document.createElement("input");
		field1.setAttribute("type","hidden");
		field1.setAttribute("name","userType");
		field1.setAttribute("value","WU");
		document.login.appendChild(field1);

		var field2 = document.createElement("input");
		field2.setAttribute("type","hidden");
		field2.setAttribute("name","PROCESS");
		field2.setAttribute("value","1");
		document.login.appendChild(field2);

		var field3 = document.createElement("input");
		field3.setAttribute("type","hidden");
		field3.setAttribute("name","isTrackingLogged");
		field3.setAttribute("value","false");
		document.login.appendChild(field3);

		var field4 = document.createElement("input");
		field4.setAttribute("type","hidden");
		field4.setAttribute("name","BV_UseBVCookie");
		field4.setAttribute("value","yes");
		document.login.appendChild(field4);

		var field5 = document.createElement("input");
		field5.setAttribute("type","hidden");
		field5.setAttribute("name","redirectPage");
		field5.setAttribute("value","");
		document.login.appendChild(field5);

		var field6 = document.createElement("input");
		field6.setAttribute("type","hidden");
		field6.setAttribute("name","inPopUp");
		field6.setAttribute("value","");
		document.login.appendChild(field6);

		var field7 = document.createElement("input");
		field7.setAttribute("type","hidden");
		field7.setAttribute("name","nextUrl");
		field7.setAttribute("value","http://www.maiellano.com/includes/checkcookie.php?companyID=MAEL&partnerID=MAEL&nextUrl=http://www.maiellano.com/");
		document.login.appendChild(field7);
		
	  var theForm=document.login;
	  theForm.action = "http://ww2.maiellano.com/ipmstage/custmgmt/wu_login.jsp";
	  theForm.submit();
	}
	else if (txt.match('Travel Agent')){

		var field1 = document.createElement("input");
		field1.setAttribute("type","hidden");
		field1.setAttribute("name","userType");
		field1.setAttribute("value","TA");
		document.login.appendChild(field1);

		var field2 = document.createElement("input");
		field2.setAttribute("type","hidden");
		field2.setAttribute("name","PROCESS");
		field2.setAttribute("value","A");
		document.login.appendChild(field2);

		var field3 = document.createElement("input");
		field3.setAttribute("type","hidden");
		field3.setAttribute("name","dontShow");
		field3.setAttribute("value","");
		document.login.appendChild(field3);

		var field4 = document.createElement("input");
		field4.setAttribute("type","hidden");
		field4.setAttribute("name","referer");
		field4.setAttribute("value","http://www.maiellano.com/");
		document.login.appendChild(field4);

		var field5 = document.createElement("input");
		field5.setAttribute("type","hidden");
		field5.setAttribute("name","nextUrl");
		field5.setAttribute("value","http://www.maiellano.com/includes/checkcookie.php?companyID=MAEL&partnerID=MAEL&nextUrl=");
		document.login.appendChild(field5);
		
	  var theForm=document.login;
	  theForm.action = "http://ww2.maiellano.com/ipmstage/custmgmt/ta_login.jsp";
	  theForm.submit();
	}	
}	

function doSubmit2() {
 txt=document.login2.userTypeS2.options[document.login2.userTypeS2.selectedIndex].text;
 if(document.login2.userTypeS2.options[document.login2.userTypeS2.selectedIndex].value == "none")
{
	document.getElementById("userTypeS2").style.background = "#cc0000";

}
	else if (txt.match('Customer')){
	
		var field1 = document.createElement("input");
		field1.setAttribute("type","hidden");
		field1.setAttribute("name","userType");
		field1.setAttribute("value","WU");
		document.login2.appendChild(field1);

		var field2 = document.createElement("input");
		field2.setAttribute("type","hidden");
		field2.setAttribute("name","PROCESS");
		field2.setAttribute("value","1");
		document.login2.appendChild(field2);

		var field3 = document.createElement("input");
		field3.setAttribute("type","hidden");
		field3.setAttribute("name","isTrackingLogged");
		field3.setAttribute("value","false");
		document.login2.appendChild(field3);

		var field4 = document.createElement("input");
		field4.setAttribute("type","hidden");
		field4.setAttribute("name","BV_UseBVCookie");
		field4.setAttribute("value","yes");
		document.login2.appendChild(field4);

		var field5 = document.createElement("input");
		field5.setAttribute("type","hidden");
		field5.setAttribute("name","redirectPage");
		field5.setAttribute("value","");
		document.login2.appendChild(field5);

		var field6 = document.createElement("input");
		field6.setAttribute("type","hidden");
		field6.setAttribute("name","inPopUp");
		field6.setAttribute("value","");
		document.login2.appendChild(field6);

		var field7 = document.createElement("input");
		field7.setAttribute("type","hidden");
		field7.setAttribute("name","nextUrl");
		field7.setAttribute("value","http://www.centralholidays.com/tools/checkcookie.php?companyID=CHT&partnerID=CHT&nextUrl=http://www.centralholidays.com/");
		document.login2.appendChild(field7);
		
	  var theForm=document.login2;
	  theForm.action = "http://ww2.centralholidays.com/ipmstage/custmgmt/wu_login.jsp";
	  theForm.submit();
	}
	else if (txt.match('Travel Agent')){

		var field1 = document.createElement("input");
		field1.setAttribute("type","hidden");
		field1.setAttribute("name","userType");
		field1.setAttribute("value","TA");
		document.login2.appendChild(field1);

		var field2 = document.createElement("input");
		field2.setAttribute("type","hidden");
		field2.setAttribute("name","PROCESS");
		field2.setAttribute("value","A");
		document.login2.appendChild(field2);

		var field3 = document.createElement("input");
		field3.setAttribute("type","hidden");
		field3.setAttribute("name","dontShow");
		field3.setAttribute("value","");
		document.login2.appendChild(field3);

		var field4 = document.createElement("input");
		field4.setAttribute("type","hidden");
		field4.setAttribute("name","referer");
		field4.setAttribute("value","http://www.centralholidays.com/");
		document.login2.appendChild(field4);

		var field5 = document.createElement("input");
		field5.setAttribute("type","hidden");
		field5.setAttribute("name","nextUrl");
		field5.setAttribute("value","http://www.centralholidays.com/tools/checkcookie.php?companyID=CHT&partnerID=CHT&nextUrl=");
		document.login2.appendChild(field5);
		
	  var theForm=document.login2;
	  theForm.action = "http://ww2.centralholidays.com/ipmstage/custmgmt/ta_login.jsp";
	  theForm.submit();
	}	
}

var errArray = new Array();

	var i=0;
	//This function validates the form in Results Page.
	function onSubmitTA()
	{
	i=0;

	validateIATA(trim(document.newTA.IATA.value));
	//alert(document.newTA.IATA.value);
	//validateIATAMax(trim(document.newTA.IATA.value));
	
 	if (i > 0) {

        	if (i==1) {

			var errString = "";

            		errString = errArray[1].substring(3,errArray[1].length -1);

            		alert(errString);

        		}

        else {

    		var errString = "";

    		for(var k=1;k<= i; k ++){

    	 	    errString = errString + errArray[k];

            }

            alert(errString);

        }

    }

    else {

	document.newTA.action="http://ww2.centralholidays.com/ipmstage/custmgmt/iata.jsp";
	document.newTA.submit();
    }
	errArray = null;
	errArray = new Array();
	i = 0;
}

function numbersonly(myfield, e, dec) {
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);

  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
    return true;

  // decimal point jump
  else if (dec && (keychar == ".")) {
    myfield.form.elements[dec].focus();
    return false;
  } else
    return false;
}

function validateFields(Str) {

 	   if (Str == null || Str == "" ) {
	       i = i + 1;
	     errArray[i]= i + ". All Fields are Mandatory.\n";
 		}
	 }

function validateIATA(Str) {
 	   if ((Str.length < 8)) {
	       i = i + 1;

	     errArray[i]= i + ". Please enter a valid IATA / CLIA!\n";
	     document.newTA.IATA.focus();
	   }
	 }

/*function validateIATAMax(Str) {
 	   if (Str == null || Str == "" || Str <= 8) {
	       i = i + 1;
	     errArray[i]= i + ". Invalid IATA / CLIA. Please enter a valid IATA / CLIA!\n";
	     document.newTA.IATA.focus();
 		}
	 }*/
function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}




function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateFormEmail(){
	var emailID=document.fpass.fpEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
/******************************************************END LOGIN AND VALIDATION JS********************************************************************/

 
/******************************************************Clear Input Field*************************************************************************/

function clearText(theField)
{
	if (theField.defaultValue == theField.value){
		if(theField.defaultValue == "Password"){
			theField.type = "password";
		}
		theField.value = '';
	}
}

function addText(theField)
{
	if (theField.value == ''){
		if(theField.type == "password"){
			theField.type = "text";
		}
	theField.value = theField .defaultValue;
	}
}

/******************************************************Clear Input Field*************************************************************************/


/******************************************************tool tip start*************************************************************************/

function simple_tooltip(target_items, name){
 jQuery(target_items).each(function(i){
		jQuery("body").append("<div style='display:none' class='"+name+"' id='"+name+i+"'><p>"+jQuery(this).attr('title')+"</p></div>");
		var my_tooltip = jQuery("#"+name+i);
		
		if(jQuery(this).attr("title") != "" && jQuery(this).attr("title") != "undefined" ){
		
		jQuery(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({opacity:0.9, display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				var border_top = jQuery(window).scrollTop(); 
				var border_right = jQuery(window).width();
				var left_pos;
				var top_pos;
				var offset = 20;
				if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
					left_pos = kmouse.pageX+offset;
					} else{
					left_pos = border_right-my_tooltip.width()-offset;
					}
					
				if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
					top_pos = border_top +offset;
					} else{
					top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}	
				
				
				my_tooltip.css({left:left_pos, top:top_pos});
		}).mouseout(function(){
				my_tooltip.css({left:"-9999px"});				  
		});
		
		}
		
		
		
	});
}

	
	
jQuery(document).ready(function(){
	 simple_tooltip("a","tooltip");
	
	$("#booking").click(function(){
		$(".booking2").show();
	});
});

/******************************************************tool tip end*************************************************************************/

function linkToDynamicPage() {
  window.open('http://ww2.maiellano.com/ipmstage/custmgmt/forgot_password_popup.jsp?dontShow=header+leftnav+trailer','PASSWORD',"width=520,height=320,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,alwaysRaised=1").focus();
  //window.open ("http://www.javascript-coder.com","mywindow","location=1,status=1,scrollbars=1,width=100,height=100");
}
