// JavaScript Document
function masterClass(){
	
	this.createCookie=function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	};

	this.readCookie=function (name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	};
	
	this.eraseCookie=function (name) {
		createCookie(name,"",-1);
	};


	//hightlight menu
	
	this.highlightNav=function(Obj,className){
		$(Obj).className=className;
	};
	
	this.show=function(Obj){
		$(Obj).style.display="block";
	};
	
	this.hide=function(Obj){
		$(Obj).style.display="none";
	};
	
	
	
	this.makeEqualSize=function(objects){
		maxH=0;
		cutObjects=objects.split(",");
		heightArray=new Array();
		if(cutObjects.length>0){
			for(i=0;i<cutObjects.length;i++){
				heightArray[i]=$(cutObjects[i]).offsetHeight;
			}
		}
		
		
		heightArray.sort();heightArray.reverse();
		if(heightArray.length>0){
			maxH=heightArray[0];
		}
		
		
		for(i=0;i<cutObjects.length;i++){
			$(cutObjects[i]).style.height=maxH+"px"
		}
		
	};
				//focus text
	this.focusTextField=function(Obj,textValue){
		if(Obj.value==textValue){
			Obj.value="";
			Obj.style.color="#333333"
		}
		else{
			Obj.style.color="#333333";
		}
			
		Obj.onblur=function(){
			if(Obj.value==""){
				Obj.value=textValue;
				Obj.style.color="#999999"
			}
			else{
				Obj.style.color="#333333";
			}
		}
	};
	
		this.validateFormFields=function(formObj,objColl,actType,url,action,messageBox,message,ajaXindicatior){
		cutFieldParams=objColl.split(",");
			//reseting
			for(i=0;i<cutFieldParams.length;i++){
				getValidType=cutFieldParams[i].split("##");
				eval("document."+formObj+"."+getValidType[0]).className="fieldClass";
			}
	
			/********Validation start******/
			ErrorCount=0
			
			for(i=0;i<cutFieldParams.length;i++){
				getValidType=cutFieldParams[i].split("##");
				if(getValidType[1]=="text"){//blank as text
					if(Trim(eval("document."+formObj+"."+getValidType[0]+".value"))=="" || Trim(eval("document."+formObj+"."+getValidType[0]+".value"))=="First Name" || Trim(eval("document."+formObj+"."+getValidType[0]+".value"))=="Last Name" ||  Trim(eval("document."+formObj+"."+getValidType[0]+".value"))=="Name" ){
						eval("document."+formObj+"."+getValidType[0]).className="fieldError";
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Should not be blank";
								$(getValidType[0]+'Label').className="colorRed";
							}
						ErrorCount++;
					}
					else{
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="";
								$(getValidType[0]+'Label').className="grayTextForLabel";
							}
					}
					if(getValidType[0]=="uname" && eval("document."+formObj+"."+getValidType[0]+".value")!=""){
						var illegalChars = /\W/;
						if (eval("document."+formObj+"."+getValidType[0]+".value").length < 5) {
							eval("document."+formObj+"."+getValidType[0]).className="fieldError";
							ErrorCount++;
						} else if (illegalChars.test(eval("document."+formObj+"."+getValidType[0]+".value")))  {
							eval("document."+formObj+"."+getValidType[0]).className="fieldError";
							ErrorCount++;
						}
					}
				}
				else if(getValidType[1]=="compare"){//compare password
					if(eval("document."+formObj+"."+getValidType[0]+".value")==""){
						eval("document."+formObj+"."+getValidType[0]).className="fieldError";
						if($(getValidType[0]+'Label')){
							$(getValidType[0]+'Label').innerHTML="Password required.";
							$(getValidType[0]+'Label').className="colorRed";
						}
						ErrorCount++;
					}
					else if(eval("document."+formObj+"."+getValidType[0]+".value").length<6){
						eval("document."+formObj+"."+getValidType[0]).className="fieldError";
						if($(getValidType[0]+'Label')){
							$(getValidType[0]+'Label').innerHTML="Password should be Minimum 6 characters.";
							$(getValidType[0]+'Label').className="colorRed";
						}
						ErrorCount++;
						}
					else if(eval("document."+formObj+".password.value")!=eval("document."+formObj+".confirmPassword.value")){
						eval("document."+formObj+"."+getValidType[0]).className="fieldError";
						if($(getValidType[0]+'Label')){
							$(getValidType[0]+'Label').innerHTML="Password mismatch";
							$(getValidType[0]+'Label').className="colorRed";
						}
						ErrorCount++;
					}
					else{
						if($(getValidType[0]+'Label')){
							$(getValidType[0]+'Label').innerHTML="";
							$(getValidType[0]+'Label').className="grayTextForLabel";
						}
					}
					
				}
				else if(getValidType[1]=="email"){//email validation
					
					if(eval("document."+formObj+"."+getValidType[0]+".value")==""){
						eval("document."+formObj+"."+getValidType[0]).className="fieldError";
						if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="E-mail ID required";
								$(getValidType[0]+'Label').className="colorRed";
						}
						ErrorCount++;
					}
					else if(!emailValidation(eval("document."+formObj+"."+getValidType[0]+".value"))){
						eval("document."+formObj+"."+getValidType[0]).className="fieldError";
						if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Valid Email ID required";
								$(getValidType[0]+'Label').className="colorRed";
						}
						ErrorCount++;
					}
					else{
						if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="";
								$(getValidType[0]+'Label').className="grayTextForLabel";
						}
					}
				}
				else if(getValidType[1]=="select"){//select box validation
					if(eval("document."+formObj+"."+getValidType[0]+".selectedIndex")==0){
						eval("document."+formObj+"."+getValidType[0]).className="fieldErrorSelect";
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Select from dropdown";
								$(getValidType[0]+'Label').className="colorRed";
							}
						ErrorCount++;
					}
					else{
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="";
								$(getValidType[0]+'Label').className="grayTextForLabel";
							}						
					}
				}
				else if(getValidType[1]=="num"){//numerical validation
					if(eval("document."+formObj+"."+getValidType[0]+".value")==""){
						eval("document."+formObj+"."+getValidType[0]).className="fieldError";
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Should not be blank";
								$(getValidType[0]+'Label').className="colorRed";
							}
						ErrorCount++;
					}
					else if(isNaN(eval("document."+formObj+"."+getValidType[0]+".value"))){
						eval("document."+formObj+"."+getValidType[0]).className="fieldError";
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Should be numerical value";
								$(getValidType[0]+'Label').className="colorRed";
							}
						ErrorCount++;
					}//else if
					else if(getValidType[3]!="undefined" && parseInt(eval("document."+formObj+"."+getValidType[0]+".value"))<=parseInt(getValidType[3])){
							eval("document."+formObj+"."+getValidType[0]).className="fieldError";
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Should be greater than "+getValidType[3];
								$(getValidType[0]+'Label').className="colorRed";
							}
							ErrorCount++;
					}	
					else if(getValidType[2]!="undefined" && parseInt(eval("document."+formObj+"."+getValidType[0]+".value"))>=parseInt(getValidType[2])){
							eval("document."+formObj+"."+getValidType[0]).className="fieldError";
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Should be lesser than "+getValidType[2];
								$(getValidType[0]+'Label').className="colorRed";
							}
							ErrorCount++;
					}
									
					else{
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="";
								$(getValidType[0]+'Label').className="grayTextForLabel";
							}						
					}
				}//else if email blank
				else if(getValidType[1]=="notblankEmail"){//numerical validation
					if(eval("document."+formObj+"."+getValidType[0]+".value")!=""){
						if(!emailValidation(eval("document."+formObj+"."+getValidType[0]+".value"))){
							eval("document."+formObj+"."+getValidType[0]).className="fieldError";
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Please enter a valid email Address";
								$(getValidType[0]+'Label').className="colorRed";
							}
							
							ErrorCount++;
						}
						else{
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="";
								$(getValidType[0]+'Label').className="grayTextForLabel";
							}
						}
					}
				}//else if 

				////*This validating List box Multiple Selection required*/
				else if(getValidType[1]=="list"){
						countSel=0;
						for(var j=0; j<eval("document."+formObj+"."+getValidType[0]+".length"); j++) {
							if(eval("document."+formObj+"."+getValidType[0])[j].selected == true){
								countSel++;
							}
						}
						if(countSel<1){
							eval("document."+formObj+"."+getValidType[0]).className="redBorderSelect";
								if($(getValidType[0]+'Label')){
									$(getValidType[0]+'Label').innerHTML="Select one or more item from list box";
									$(getValidType[0]+'Label').className="colorRed";
								}
								ErrorCount++;
						}
						else if(countSel==1 && eval("document."+formObj+"."+getValidType[0])[0].value=="-1"){
								if($(getValidType[0]+'Label')){
									$(getValidType[0]+'Label').innerHTML=eval("document."+formObj+"."+getValidType[0])[0].text.replace(/--/gi, "");
									$(getValidType[0]+'Label').className="colorRed";
								}
								ErrorCount++;
						}
						else{
								if($(getValidType[0]+'Label')){
									$(getValidType[0]+'Label').innerHTML="";
									$(getValidType[0]+'Label').className="grayTextForLabel";
								}						
						}
				}
				////*End of ListBox Validation*/
								////*End of checkBox Validation*/
				else if(getValidType[1]=="check"){
					countChked=0;
						for(var j=0; j<eval("document."+formObj+"."+getValidType[0]+".length"); j++) {
							if(eval("document."+formObj+"."+getValidType[0])[j].checked == true){
								countChked++;
							}
						}	
						if(countChked<1){
							
								//eval("document."+formObj+"."+getValidType[0]+"DIV").className="redBorderSelect";
								$(getValidType[0]+"DIV").className="fieldError";
								if($(getValidType[0]+'Label')){
									$(getValidType[0]+'Label').innerHTML="Check one or more items";
									$(getValidType[0]+'Label').className="colorRed";
								}
								ErrorCount++;
						}
						else{
								$(getValidType[0]+"DIV").className="";
								if($(getValidType[0]+'Label')){
									$(getValidType[0]+'Label').innerHTML="";
									$(getValidType[0]+'Label').className="grayTextForLabel";
								}						
						}
				}
				
				else if(getValidType[1]=="captcha") {
					if(Trim(eval("document."+formObj+"."+getValidType[0]+".value"))=="" ){
						eval("document."+formObj+"."+getValidType[0]).className="redBorder";
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="Security code should not be blank";
								$(getValidType[0]+'Label').className="colorRed";
							}
						ErrorCount++;
					}
					else{
							if($(getValidType[0]+'Label')){
								$(getValidType[0]+'Label').innerHTML="";
								$(getValidType[0]+'Label').className="grayTextForLabel";
							}
					}
				
				}
				
			}///for
			
			/********Validation over******/
			
			
			/*****start validation result printing****/
			if(ErrorCount>0){
				if(messageBox!=""){
					$(messageBox).className="messageError";
					show(messageBox)
				
					if(message!=""){
						$(messageBox).innerHTML=message
					}
					else {
						$(messageBox).innerHTML="Please fill all mandatory fields marked as *"
					}	
					
				}
				else{
					if($('messageBox')){
						$('messageBox').className="messageError";
						show('messageBox')
					
						if(message!=""){
							$('messageBox').innerHTML=message
						}
						else {
							$('messageBox').innerHTML="Please fill all mandatory fields marked as *"
						}	
					}
				}
				
				
			}
			else{
				if(messageBox!=""){
					$(messageBox).className="messageSucess";
					hide(messageBox);
				}
				else{
					if($('messageBox')){
						$('messageBox').className="messageSucess";
						hide('messageBox');
					}
				}
				if(actType=="MULTIPART"){
					
				}
				else{
					
					
					if(ajaXindicatior!=""){
						show(ajaXindicatior);
					}
					else{
						if($('ajaxStatusMain')){
							show('ajaxStatusMain');
						}
					}

					disableForm(formObj,true)
					//alert(ajax.serialize(formObj));
					
					if(url=="URLinActionTag"){
						url=$(formObj).action;
					}
					
					ajax.getNoCache(url+"?action="+action+"&"+ajax.serialize(formObj),"stratos.updateCalculationStatus",ajaXindicatior,formObj,messageBox)
				}
				
			}
			
			/*****start validation result printing****/
			
	}
	
	this.updateCalculationStatus=function(result,a,fO,mB){
		//alert(result);
		//return false;
		if($(a))hide(a);
		cutResponseText=result.split("++++");
		if(Trim(cutResponseText[0])=="MailSent"){
			$('inputContainerTPF').className="messageSucess";
			show('inputContainerTPF');
			$('inputContainerTPF').innerHTML=cutResponseText[1];
			setTimeout("hide('ajaxContentMain')", 6000);
		}
		else if(Trim(cutResponseText[0])=="MailSentSignUP"){
			$(fO).reset();
			disableForm(fO,false);
			hide('inputContainerSIGNUP');
			show('outputContainerSIGNUP');
			$('outputContainerSIGNUP').className="messageSucess";
			$('outputContainerSIGNUP').innerHTML=cutResponseText[1];
			
			setTimeout("$('outputContainerSIGNUP').innerHTML='';hide('outputContainerSIGNUP');hide('signUpDIV');show('inputContainerSIGNUP');", 6000);
		}
		else if(Trim(cutResponseText[0])=="MailSentContact"){
			$(fO).reset();
			disableForm(fO,false);
			hide('inputContainerContact');
			show('outputContainerContact');
			$('outputContainerContact').className="messageSucess";
			$('outputContainerContact').innerHTML=cutResponseText[1];
			
			setTimeout("$('outputContainerContact').innerHTML='';hide('outputContainerContact');hide('signUpDIV');show('inputContainerContact');", 6000);
		}

	}
	
	this.mail=function(mailId){
		location.href="mailto:"+mailId+"@stratoslifestyles.com"
	}
	
}

stratos=new masterClass();

/*****AJAX functions start****/
function $(e){if(typeof e=='string')e=document.getElementById(e);return e};

function hide(obj){if($(obj)) $(obj).style.display="none";}

function show(obj){if($(obj)) $(obj).style.display="block";}

function disableForm(Obj,type){
	var inputCol=new Array();
	
	inputFields=$(Obj).getElementsByTagName('input');
	for(i=0;i<inputFields.length;i++){
		inputFields[i].disabled=type
	}
	
	selFields=$(Obj).getElementsByTagName('select');
	for(i=0;i<selFields.length;i++){
		selFields[i].disabled=type
	}
	
	textareaFields=$(Obj).getElementsByTagName('textarea');
	for(i=0;i<textareaFields.length;i++){
		textareaFields[i].disabled=type
	}

}
function parseAndEvalScripts(sIN){var sHTML="";if(sIN.indexOf("<script")>=0){var oHTML=sIN.split("</script>");for(iHTML=0;iHTML<oHTML.length;iHTML++){if(oHTML[iHTML].indexOf("<script")>= 0) {sHTML=oHTML[iHTML];sHTML=Right(sHTML,sHTML.length-sHTML.indexOf("<script")-7);sHTML=Right(sHTML,sHTML.length-sHTML.indexOf(">")-1);eval(sHTML);}}}};


function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};

ajax={};
ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
//ajax.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
ajax.serialize=function(f){var g=function(n){return $(f).getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);var sOutput = i.concat(s).concat(t).join('&'); while (sOutput.indexOf('&&')>0) sOutput = sOutput.replace("&&","&"); return sOutput;}; // i've modified to clear out instances of "&&" in the POSTback

ajax.send=function(u,f,m,a){
	var x=ajax.x();
	x.open(m,u,true);
	x.onreadystatechange=function(){if(x.readyState==4)eval(f)((x.responseText))};
	if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	x.send(a)
	};

ajax.sendNoCache=function(u,f,m,a,fO,mB){ 
	u = u + (u.indexOf('?') < 0 ? '?' : '&') + 'noCache=' + new Date().getTime();
	var x=ajax.x();
	x.open(m,u,true);
	x.onreadystatechange=function(){if(x.readyState==4)eval(f)((x.responseText),a,fO,mB);  };
	if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	x.send(a)
};

ajax.get=function(url,func){ajax.send(url,func,'GET')};

ajax.getNoCache=function(url,func,ajaxIndicator,formObj,messageBox){url = url + (url.indexOf('?') < 0 ? '?' : '&') + 'noCache=' + new Date().getTime();ajax.sendNoCache(url,func,'GET',ajaxIndicator,formObj,messageBox)};

ajax.gets=function(url){var x=ajax.x();x.open('GET',url,false);x.send(null);return x.responseText};

ajax.getsNoCache=function(url){url = url + (url.indexOf('?') < 0 ? '?' : '&') + 'noCache=' + new Date().getTime();var x=ajax.x();x.open('GET',url,false);x.send(null);return x.responseText};

ajax.post=function(url,func,args){ajax.send(url,func,'POST',args)};

ajax.postNoCache=function(url,func,args){ajax.sendNoCache(url,func,'POST',args)};

ajax.update=function(url,elm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.get(url,f);};

ajax.updateNoCache=function(url,elm,loaderElm){var e=$(elm);if($(loaderElm)) show(loaderElm); var f=function(r){e.innerHTML=r;hide(loaderElm)};ajax.getNoCache(url,f);};

ajax.submit=function(url,elm,frm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.post(url,f,ajax.serialize(frm))};

ajax.submitNoCache=function(url,elm,frm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.postNoCache(url,f,ajax.serialize(frm))};
/****ajax functions end*****/
		
/*****Triming space of Given text*****/

	function emailValidation(ObjValue){
				cutEmailAt=ObjValue.split("@");
				cutEmailDot=ObjValue.split(".");
				if(cutEmailAt.length<2 || cutEmailAt.length>2 ){
					return false;
				}
				else if(cutEmailDot.length<2){
					return false;
				}
				else{
					return true; 
				}
		}
		

			function Trim(s) 
			   {
				// Remove leading spaces and carriage returns
				while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
				 { s = s.substring(1,s.length); }
				 
				// Remove trailing spaces and carriage returns
			 while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
				 { s = s.substring(0,s.length-1); }
				 
				 
				return s;
			   }
			   
	function changeOpac(opacity, id) { 
		var object = document.getElementById(id).style; 
		if(object){
			object.opacity = (opacity / 100); 
			object.MozOpacity = (opacity / 100); 
			object.KhtmlOpacity = (opacity / 100); 
			object.filter = "alpha(opacity=" + opacity + ")"; 
			object="";
		}
	}

/**************************************************************************/


