var loadstatustext='<img src="images/loading.gif" />';
var rootdomain="http://"+window.location.hostname

function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function getFormAsString(formName){
    
	  //Setup the return String
	  returnString ="";
	        
	  //Get the form values
	  formElements=document.forms[formName].elements;
	        
	  //loop through the array, building up the url
	  //in the format '/strutsaction.do&name=value'
	 
	  for(var i=formElements.length-1;i>=0; --i ){
	        //we escape (encode) each value
	        returnString+="" 
	        +escape(formElements[i].name)+"=" 
	        +escape(formElements[i].value)+"&";
	 }
	        
	 //return the values
	 return returnString; 
	}
		
function ajaxpage(url, containerid){
	//alert(containerid);
	var page_request = false;
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
			}
	}else
		return false
	
	if(containerid == 'contentDIv'){
		document.getElementById(containerid).innerHTML=loadstatustext;
	}
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}
	page_request.open('GET', url, true)
	page_request.send(null)
}


function ajaxpageform(url, containerid,formName){
	var page_request = false;
	
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}catch (e){}
		}
	}else
		return false
	

	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}
	
	var parameters = getFormAsString(formName);	
	document.getElementById(containerid).innerHTML=loadstatustext		
    page_request.open('POST', url, true);
    page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    page_request.setRequestHeader("Content-length", parameters.length);
    page_request.setRequestHeader("Connection", "close");
    page_request.send(parameters);
}


		function loadpage(page_request, containerid){
		 	if (page_request.readyState == 4 ){
				//&& (page_request.status==200) || window.location.href.indexOf("http")==-1
				
				var	resp_str = LTrim(RTrim(page_request.responseText));
				//alert(resp_str);
				if(resp_str.indexOf("Your account has been updated successfully!") >= 0 || resp_str.indexOf("Your password has been updated successfully!") >= 0 ){
					//alert('I am where u want it to be');
					var x = Math.random();
					ajaxpage("refreshProfile.do?y="+x,'profileDiv');
					document.getElementById(containerid).innerHTML=page_request.responseText;
					//document.location.href="profile.do";
					//document.getElementById("messageDiv2").innertHTML= "Your account has been updated successfully!";
				}	
				if(containerid == 'errormsg'){
					if(resp_str == 'INVAILD_USER_1'){
						clearlogin();
						alert('Invalid username or password !');
					}else if(resp_str == 'INVAILD_USER_2'){
						alert('Invalid username or password !');
					}else if(resp_str == 'VAILD_USER_1'){
						var x = Math.random();
						ajaxpage('showUserHome.do?y='+x,'loginpage');
					}else if(resp_str == 'VAILD_USER_1'){
						var x = Math.random();
						ajaxpage('showUserHome.do?y='+x,'loginpage');
					}else if(resp_str == 'SUCCESS_PASSWORD_RESET'){
						alert("Password Reset Successfully !");
					}else if(resp_str == 'FAILURE_PASSWORD_RESET'){
						alert("Password Reset Failed !");
					}else if(resp_str == 'VAILD_USER_RESERVPAGE'){
						var x = Math.random();
						ajaxpage('showUserHome.do?y='+x,'loginpage');
						document.location.href="displayHotelReservation.do";
					}else if(resp_str == 'VAILD_USER_PROFILE'){
						var x = Math.random();
						ajaxpage('showUserHome.do?y='+x,'loginpage');
						document.location.href="showGuestUserHome.do?tabId=profile";
					}
					//
					
				}else if(containerid=='stateId'){
					var state = resp_str.split(";");
					var id=state[0].split(",");
					var name=state[1].split(",");
					
					document.searchHotelForm.state.options[0]=new Option('Select State','');
					for(var i=0;i<id.length;i++){
						document.searchHotelForm.state.options[i+1]=new Option(name[i],id[i]);
						}
				}else if(containerid=='cityId'){
					
					var len = document.searchHotelForm.city.options.length;
					
					for(var j=0;j<len;j++){
						document.searchHotelForm.city.options[0]=null
						}
					var len2 = document.searchHotelForm.city.options.length;
					
					var city = resp_str.split(";");
					var id=city[0].split(",");
					var name=city[1].split(",");
					var selected = city[2];
					document.searchHotelForm.city.options[0]=new Option('Select City','');
					document.searchHotelForm.city.options[0].selected = true;
					for(var i=0;i<id.length;i++){
						document.searchHotelForm.city.options[i+1]=new Option(name[i],id[i]);
						if(selected != '' && name[i] == selected){
							document.searchHotelForm.city.options[i+1].selected = true;
						}
						
					}
					var len3 = document.searchHotelForm.city.options.length;
					
				}else if(containerid=='totalCost'){
					document.getElementById(containerid).innerHTML=page_request.responseText+'$';
					document.getElementById('taxes').innerHTML=page_request.responseText/10+'$';
				}else if(containerid == 'profileDivId'){
					document.getElementById(containerid).innerHTML=page_request.responseText;
					if(document.getElementById("currentPassword") != undefined){
						document.getElementById("currentPassword").focus();
					}else if(document.forms[0].name != "undefined"){
						document.forms[0].name.focus();
					}
				}else if(containerid=='comparisonReportDiv'){
					document.getElementById(containerid).innerHTML=page_request.responseText;
					clearTimeout(waitMsgTimeOut);
					//showProgressDots(4);
					hideCompAuditImg('comparison_ca_image');
				}else if(containerid=='comparisonReportDivId'){
					document.getElementById(containerid).innerHTML=page_request.responseText;
					clearTimeout(waitMsgTimeOut);
					//showProgressDots(4);
					hideCompLoadingImg('comparison_ca_image');
				}else if(containerid=='confirmOrderDivId'){
					//document.getElementById(containerid).innerHTML="";
					if(resp_str.indexOf("orderConfirmed") >= 0){
						if(document.forms['payPalOrderForm'] != 'undefined'){
							document.forms['payPalOrderForm'].submit();
						}
					}else{
						document.getElementById(containerid).innerHTML = resp_str;
					}
				}else{
					document.getElementById(containerid).innerHTML=page_request.responseText;
				}	
				
			}	
		}




function showChangePassword(){
	var x = Math.random();
	ajaxpage("showChangePasswordScreen.do?y="+x,'contentDiv');
}
//Method to change the password
function changeUserPassword(password){
	var x = Math.random();
	document.getElementById('profileDiv').innerHTML="";
	ajaxpageform("changePassword.do?y="+x,'profileDivId','changePassword');
}
function showForgotPassword(context){
	var x = Math.random();
	ajaxpage(context+"/forgotPasswordForm.do?y="+x,'forgotContentDiv');
	document.getElementById("loginDiv").style.display = "none";
	if(sendForgotPwd){
		document.getElementById('forgotContentDiv').innerHTML=sendForgotTxt;
	}
	document.getElementById("forgotContentDiv").style.display = "block";
	
	
	return false;
}
var sendForgotPwd = false;
var sendForgotTxt = "";
function sendForgotPassword(context){
	var x = Math.random();
	sendForgotPwd = true;
	sendForgotTxt = document.getElementById('forgotContentDiv').innerHTML;
	ajaxpageform(context+"/forgotPassword.do?y="+x,'forgotContentDiv','forgotPassword');
	document.getElementById('forgotContentDiv').innerHTML ="<img src='images/wait.gif' style='vertical-align:middle' />";
}
function showEditProfileScreen(){
	var x = Math.random();
	ajaxpage("showEditUserScreen.do?y="+x,'contentDiv');
}
function editProfile(){
	var x = Math.random();
	ajaxpageform("editUser.do?y="+x,'profileDivId','registrationForm');
}

function cancelInProfile(){
	document.getElementById('contentDiv').innerHTML="";
}
function cancelInForgotPassword(){
	document.getElementById('forgotContentDiv').innerHTML="";
}
function showProfile(){
	var x = Math.random();
	document.getElementById('profileDivId').innerHTML="";
	ajaxpage("refreshProfile.do?y="+x,'profileDiv');
}
function showMyAcChangePassword(){
	var x = Math.random();
	document.getElementById('profileDiv').innerHTML="";
	ajaxpage("showChangePasswordScreen.do?y="+x,'profileDivId');
}
function showMyAcEditProfileScreen(){
	var x = Math.random();
	document.getElementById('profileDiv').innerHTML="";
	ajaxpage("showEditUserScreen.do?y="+x,'profileDivId');
}
function cancelInProfileDiv(){
	document.getElementById('profileDivId').innerHTML="";
}
//Code for validating Comprehensive Audit Form
function validateURLs(){
	 var domain = document.comprehensiveAuditForm.domainName.value;
	 var comp1 = document.comprehensiveAuditForm.competitor1.value;
	 var comp2 = document.comprehensiveAuditForm.competitor2.value;
	 var comp3 = document.comprehensiveAuditForm.competitor3.value;

	 var errorMessage = "";
	 var compError = "Invalid Competitor.  Please enter a valid Domain Name<br/>"
	 if(domain.length > 0){
		 if(! isValidURL(domain)){
			 errorMessage = "Invalid Website Name.  Please enter a valid Website Name<br/>";
		 }
	 }else{
		 errorMessage = "Website Name is required<br/>";
	 }
	 if((comp1.length > 0 && comp1 != "Competitor 1") && ! isValidURL(comp1)){
		errorMessage += compError;
	 }else if((comp2.length > 0 && comp2 != "Competitor 2") && ! isValidURL(comp2)){
		errorMessage += compError;
	 }else if((comp3.length > 0 && comp3 != "Competitor 3") && ! isValidURL(comp3)){
		errorMessage += compError;
	 }
	 var placeHolderEle = document.getElementById("errorDiv2");
	 if(errorMessage.length > 0){
		 placeHolderEle.innerHTML = errorMessage;
		 return false;
	 }else{
		 placeHolderEle.innerHTML = "";
		 return true;
	 }
}

function validateCompreAuditForm(){
	 var comp1 = document.comprehensiveAuditForm.competitor1;
	 var comp2 = document.comprehensiveAuditForm.competitor2;
	 var comp3 = document.comprehensiveAuditForm.competitor3;
	 var domainName = document.comprehensiveAuditForm.domainName;
	 
	 // convert domain names to lower case
	 if(comp1.value != "Competitor 1"){
		 comp1.value = comp1.value.toLowerCase();
	 }
	 if(comp2.value != "Competitor 2"){
		 comp2.value = comp2.value.toLowerCase();
	 }
	 if(comp3.value != "Competitor 3"){
		 comp3.value = comp3.value.toLowerCase();
	 }
	 domainName.value = domainName.value.toLowerCase();
	 
	 if(validateURLs()){
		 //removeSuffix(comp1,"1.");
		 //removeSuffix(comp2,"2.");
		 //removeSuffix(comp3,"3.");
		 document.forms[0].submit();
		 return true;
	 }else{
		 return false
	 }
}

function focusInCheck(comp,value){
	 var item = comp.value;
	 if(item == value){
		 comp.value = "";
	 }
}

function focusOutCheck(comp,value){
	 var item = comp.value;
	 if(item.length == 0){
		 comp.value = value;
	 }
}

/*function removeSuffix(comp,suffix){
	var value = comp.value;
	if(comp != null && value.length > 0){
		if(value == suffix){
			comp.value = "";
		}
	}
}*/

function removeSuffix(comp,suffix){
	var value = comp.value;
	if(comp != null && value.length > 0){
		if(value == suffix){
			comp.value = "";
		}
	}
}

function isValidURL(domainName)
{
	//var placeHolderEle = document.getElementById("errorDiv2");
	domainName = domainName.toLowerCase();
	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 = domainName;
	if(mai == ""){
		 //placeHolderEle.innerHTML = "Please enter a website address.";
		 return false;
	}
	
	//alert(mai.lastIndexOf("."));
 	//alert("Before--"+mai);
 	mai = mai.replace("http://","");
 	mai = mai.replace("https://","");

	// www |  wwww validation
    if(mai.indexOf('w.') != -1){  // if w. found
         var wValStr = mai.substring(0,mai.indexOf('.'));
         var wRepeatText = "";
         for(var k = 0; k < wValStr.length; k++){
            wRepeatText = wRepeatText+'w';
         }
         if(wRepeatText == wValStr){  // if matched string contains only 'w' character then check for validation (www or wwww) otherwise teat it as valid domain.
          if(wValStr != "www" && wValStr != "wwww"){
           return false;
          }
         }
         
    }
	
	if(mai.charAt(mai.length-1) == '/'){ // if domianName contains / at the end then allow as it is valid domain name
		mai = mai.substring(0,mai.length-1);
	}
	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)
		{
			 //placeHolderEle.innerHTML = "Invalid Website address.  Please enter a valid website address.";
			 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)	
				 {
					
			    	//placeHolderEle.innerHTML = "Invalid Website address.  Please enter a valid website address.";
			        return false;
				 }
			  }
			else	{
				//placeHolderEle.innerHTML = "Invalid Website address.  Please enter a valid website address.";
				 return false;
			  }
			}
		}
	}
	else
	{
	 //placeHolderEle.innerHTML = "Invalid Website address.  Please enter a valid website address.";
	 return false;
	}	
	//document.forms[0].submit();
	return true;
}

//Code for validating Comprehensive Audit Form end

function saveDetailReport(){
	
	updateTextArea('coverLetter');
	updateTextArea('appendix');
	updateTextArea('otherSuggestions');
	return true;
}

function populateSelectLinkId(linkId){
		if(document.getElementById(linkId)!=undefined){
			document.getElementById(linkId).style.color="#ff7400";
		}
}
function saveComparisonReport(){
	var x = Math.random();
	//var domainName = document.forms[3].comparisionDomainName1.value;
	//var comparisionDomainName = document.forms[3].comparisionDomainName2.value;
	var domainName =  document.getElementById("comparisionDomainName1").value;
	var comparisionDomainName = document.getElementById("comparisionDomainName2").value;
	
	var compUrl = "startAnalysisWithComparision.do?y="+x+"&domainName="+domainName+"&comparisionDomainName="+comparisionDomainName;
	ajaxpage(compUrl,'tempDivId');
}
function redirectToComparisonReport(){
	var x = Math.random();
	ajaxpage("showComparisonReport.do?y="+x,'comparisonReportDiv');
}

//scripts for comparison report popup

function showSampleComparisonReport()
{
	var x = Math.random();
	ajaxpage("sampleComparisonReport.do?y="+x,'cr_image');
	crr = "scr";
	var mask = document.getElementById("mask");
	var caimg = document.getElementById("cr_image");
	mask.style.display = "block";
	caimg.style.display = "block";
	//alert(document.body.clientWidth);
	var left = (document.body.clientWidth - 1000)/2+"px";
	var top =  (document.body.clientHeight - 500)/2+"px";
	caimg.style.left = left;
	caimg.style.top = 100+"px";
	setMaskHeight(jQuery("#cr_image").height());
}

function hideComparisonReportPopup()
{
var mask = document.getElementById("mask");
var caimg = document.getElementById("cr_image");
	mask.style.display = "none";
	caimg.innerHTML = '';
	caimg.style.display = "none";
}
//sample comparison report tabs change function start here
var previousCRTabId = 'tabcr1';
var previousCRTabSpanIdLeft = 'tabcr1SpanLeftId';
var previousCRTabSpanIdRight = 'tabcr1SpanRightId';
var previousCRTabAnchorId = 'tabcr1AnchorId';

function showSelectedCRTab(id,spanIdLeft,spanIdRight,anchorId){
	
		var elemPrev = document.getElementById(previousCRTabId); // id is the ID of the element we are trying to show hide
		var elemVisPrev = elemPrev.style.display;
			if(elemVisPrev == 'block')
			{
				elemVisPrev = 'none';
			}
			//alert(previousTabId);
			elemPrev.style.display = elemVisPrev;
		var elem = document.getElementById(id); // id is the ID of the element we are trying to show hide
		var elemVis = elem.style.display;
			if(elemVis == 'none')
			{
				elemVis = 'block';
			}
			
		elem.style.display = elemVis;
		previousCRTabId = id;
		if(document.getElementById(previousCRTabSpanIdLeft)!='undefined'){
			document.getElementById(previousCRTabSpanIdLeft).className = 'left';
		}
		if(document.getElementById(previousCRTabSpanIdRight)!='undefined'){
			document.getElementById(previousCRTabSpanIdRight).className = 'right';
		}
		if(document.getElementById(previousCRTabAnchorId)!='undefined'){
			document.getElementById(previousCRTabAnchorId).className = '';
		}
		previousCRTabSpanIdLeft = spanIdLeft;
		previousCRTabSpanIdRight = spanIdRight;
		previousCRTabAnchorId = anchorId;
		if(document.getElementById(spanIdLeft)!='undefined'){
			document.getElementById(spanIdLeft).className = 'leftsel';
		}
		if(document.getElementById(spanIdRight)!='undefined'){
			document.getElementById(spanIdRight).className = 'rightsel';
		}
		if(document.getElementById(anchorId)!='undefined'){
			document.getElementById(anchorId).className = 'sel';
		}
}
// tabs change function end here


//scripts for quick report popup

function showSampleQuickReport()
{
	var x = Math.random();
	ajaxpage("sampleQuickReport.do?y="+x,'qr_image');
	crr = "sqr";
	var mask = document.getElementById("mask");
	var caimg = document.getElementById("qr_image");
	mask.style.display = "block";
	caimg.style.display = "block";
	var left = (document.body.clientWidth - 1000)/2+"px";
	var top =  (document.body.clientHeight - 500)/2+"px";
	caimg.style.left = left;
	caimg.style.top = 100+"px";
	setMaskHeight(jQuery("#qr_image").height());
}


function hideQuickReportPopup()
{
var mask = document.getElementById("mask");
var caimg = document.getElementById("qr_image");
	mask.style.display = "none";
	caimg.innerHTML = '';
	caimg.style.display = "none";
}

//sample comparison report tabs change function start here
var previousQRTabId = 'tabqr1';
var previousQRTabSpanIdLeft = 'tabqr1SpanLeftId';
var previousQRTabSpanIdRight = 'tabqr1SpanRightId';
var previousQRTabAnchorId = 'tabqr1AnchorId';

//Added the report tab click function for all reports!
function showSelectedRepTab(id, divId)
{
	if(divId == "tabqr"){
		jQuery("#tabqr1, #tabqr2, #tabqr3, #tabqr4, #tabqr5").hide();	
		jQuery("#qrli1, #qrli2, #qrli3, #qrli4, #qrli5").removeClass("sel");
		jQuery("#tabqr"+id).show();
		var dht = jQuery("#tabqr"+id).height();
		jQuery("#qrli"+id).addClass("sel");
		setMaskHeight(dht);
		//alert(id+"...."+divId);
	}
	
	
	if(divId == "tabcompr"){
		jQuery("#tabcompr1, #tabcompr2, #tabcompr3, #tabcompr4").hide();	
		jQuery("#comprli1, #comprli2, #comprli3, #comprli4").removeClass("sel");
		//jQuery("#tabcr"+id).show();
		jQuery("#tabcompr"+id).show();
		var dht = jQuery("#tabcompr"+id).height();
		//alert("#tabcr"+id);
		//alert(jQuery("#comprli"+id).addClass("sel"));
		jQuery("#comprli"+id).addClass("sel");
		setMaskHeight(dht);
		//alert(id+"...."+divId);
		
	}
	
	if(divId == "tabcr"){
		jQuery("#tabcr1, #tabcr2, #tabcr3, #tabcr4").hide();	
		jQuery("#crli1, #crli2, #crli3, #crli4").removeClass("sel");
		//jQuery("#tabcr"+id).show();
		jQuery("#tabcr"+id).show();
		var dht = jQuery("#cr_image").height();
		//alert(dht);
		jQuery("#crli"+id).addClass("sel");
		setMaskHeight(dht);
		//alert(id+"...."+divId);
		
	}
	
	if(divId == "tabdr"){
		jQuery("#tabdr1, #tabdr2, #tabdr3, #tabdr4, #tabdr5").hide();	
		jQuery("#drli1, #drli2, #drli3, #drli4, #drli5").removeClass("sel");
		jQuery("#tabdr"+id).show();
		var dht = jQuery("#ca_image").height();
		jQuery("#drli"+id).addClass("sel");
		//alert(dht);
		setMaskHeight(dht);
		//alert(id+"...."+divId);
	}
	
}

/*function setMaskHeight(ht){
	if(ht < jQuery(document).height())
	{
		ht = jQuery(document).height();	
	}
	
	jQuery("#mask").css({'position': 'absolute', 'top': 0, 'left': 0, 'width': jQuery(window).width(), 'height': ht+100});
	if(navigator.platform != 'iPad'){
	jQuery(window).resize(function() {
  		jQuery("#mask").css({'position': 'absolute', 'top': 0, 'left': 0, 'width': jQuery(window).width(), 'height': jQuery(document).height()+10});
		var left = (jQuery(window).width()-jQuery("#ca_image").width())/2;
	var top = (jQuery(window).height()-jQuery("#ca_image").height())/2;
	//alert(jQuery("#ca_image").height()+"..."+jQuery("#ca_image").width());
	
	jQuery("#ca_image").css({'top': 100, 'left': left});
	});
	}
}
*/

var fht = 0;
var fwd = 0;
var cwd = 0;
var crr = "";
jQuery(document).ready(function(){fht = jQuery(document).height(); fwd = jQuery(window).width();});
function setMaskHeight(ht){
	var tht = 0;
		if(crr == "sqr"){
			//alert("sqr");
			tht = ht+300;
		}
		else if(crr == "scr"){
			//alert("scr");
			tht = ht+250;
		}
		else if(crr == "sca"){
			//alert("sca");
			tht = ht+300;	
		}

//alert(fht+"..."+ht);
	if(tht < fht)
	{
		ht = fht;
		cwd = fwd;
	}
	else
	{
		if(crr == "sqr"){
			//alert("sqr");
			ht = ht+300;
		}
		else if(crr == "scr"){
			//alert("scr");
			ht = ht+250;
		}
		else if(crr == "sca"){
			//alert("sca");
			ht = ht+300;	
		}
		if(jQuery.browser.msie){
			cwd =fwd;
		}
		else
		{
			cwd =fwd-0;
		}
		
	}
		
	
	
	jQuery("#mask").css({'position': 'absolute', 'top': 0, 'left': 0, 'width': cwd, 'height': ht});
	if(navigator.platform != 'iPad'){
	jQuery(window).resize(function() {
  		jQuery("#mask").css({'position': 'absolute', 'top': 0, 'left': 0, 'width': jQuery(document).width(), 'height': jQuery(document).height()+10});
		var left = (jQuery(window).width()-jQuery("#ca_image").width())/2;
	var top = (jQuery(window).height()-jQuery("#ca_image").height())/2;
	//alert(jQuery("#ca_image").height()+"..."+jQuery("#ca_image").width());
	
	jQuery("#ca_image").css({'top': 100, 'left': left});
	});
	}
}



function showSelectedQRTab(id,spanIdLeft,spanIdRight,anchorId){
	
		var elemPrev = document.getElementById(previousQRTabId); // id is the ID of the element we are trying to show hide
		var elemVisPrev = elemPrev.style.display;
			if(elemVisPrev == 'block')
			{
				elemVisPrev = 'none';
			}
			//alert(previousTabId);
			elemPrev.style.display = elemVisPrev;
		var elem = document.getElementById(id); // id is the ID of the element we are trying to show hide
		var elemVis = elem.style.display;
			if(elemVis == 'none')
			{
				elemVis = 'block';
				setMaskHeight(jQuery("#"+id).height());
			}
			
		elem.style.display = elemVis;
		previousQRTabId = id;
		if(document.getElementById(previousQRTabSpanIdLeft)!='undefined'){
			document.getElementById(previousQRTabSpanIdLeft).className = 'left';
		}
		if(document.getElementById(previousQRTabSpanIdRight)!='undefined'){
			document.getElementById(previousQRTabSpanIdRight).className = 'right';
		}
		if(document.getElementById(previousQRTabAnchorId)!='undefined'){
			document.getElementById(previousQRTabAnchorId).className = '';
		}
		previousQRTabSpanIdLeft = spanIdLeft;
		previousQRTabSpanIdRight = spanIdRight;
		previousQRTabAnchorId = anchorId;
		if(document.getElementById(spanIdLeft)!='undefined'){
			document.getElementById(spanIdLeft).className = 'leftsel';
		}
		if(document.getElementById(spanIdRight)!='undefined'){
			document.getElementById(spanIdRight).className = 'rightsel';
		}
		if(document.getElementById(anchorId)!='undefined'){
			document.getElementById(anchorId).className = 'sel';
		}
}



//tabs change function end here
/*
function showReportTab(firstId,secondId, firstTabId, secondTabId){
	var secondDocId=document.getElementById(secondId);
	if(secondDocId!='undefined'){
		secondDocId.style.display="none";
		if(document.getElementById(secondTabId)!='undefined'){
			alert("test");
			document.getElementById(secondTabId).className='';
		}
	}
	var firstDocId = document.getElementById(firstId);
	if(firstDocId!='undefined'){
		firstDocId.style.display="block";
		if(document.getElementById(firstTabId)!='undefined'){
			alert("test");
			document.getElementById(firstTabId).className='sel';
		}
		
	}
}*/

//quick report form submission
function generateQuickReport(){
	var yourDomainName = document.getElementById("domainName");
	var yourDomainNameValue = yourDomainName.value;
	if(yourDomainNameValue == "www.yoursite.com"){
		yourDomainNameValue = '';
	}
	if(isValidURL(yourDomainNameValue)){
		
		//removing '/' if it is in domain Name
		if(yourDomainNameValue.charAt(yourDomainNameValue.length-1) == '/'){ // if domianName contains / then
			yourDomainName.value = yourDomainNameValue.substring(0,yourDomainNameValue.length-1);
		}
		
		document.startQuickAnalysis.action="quickreportresult";

	 	
	}else{
		return false;
	}
	return true;
	
}
/******   Submitting form with comparision website start here  *****/
var comparisionReportGenerationTime = 30000;
var waitMsgTimeOut = null;
function startAnalysisWithComparisionReport(){
	
	var yourDomainName = document.getElementById("comparisionDomainName1");
	var competitorDomainName = document.getElementById("comparisionDomainName2");
	
	var yourDomainNameValue = yourDomainName.value;
	var compDomainNameValue = competitorDomainName.value;
	if(yourDomainNameValue == "www.yoursite.com"){
		yourDomainNameValue = '';
	}
	domain_name = yourDomainNameValue;
	if(compDomainNameValue == "www.othersite.com"){
		compDomainNameValue = '';
	}
	var domainValid = isValidURL(yourDomainNameValue);
	if(domainValid){ 
			var comaparisionDomainValid = isValidURL(compDomainNameValue);
			if(comaparisionDomainValid){
				//removing '/' if it is in domain Name
				if(yourDomainNameValue.charAt(yourDomainNameValue.length-1) == '/'){ // if domianName contains / then
					yourDomainName.value = yourDomainNameValue.substring(0,yourDomainNameValue.length-1);
				}
				if(compDomainNameValue.charAt(compDomainNameValue.length-1) == '/'){ // if domianName contains / then
					competitorDomainName.value = compDomainNameValue.substring(0,compDomainNameValue.length-1);
				}
				
				//UAT script used for tracking quick repirts generated by user
				//UAT Script Start
				var loggedInStatus = 'false';
				if(document.getElementById("loggedIn")!='undefined'){
					loggedInStatus=document.getElementById("loggedIn").innerHTML;
				}
				//UAT Script End
				
				comparisonReportTracking(yourDomainNameValue,compDomainNameValue,loggedInStatus);
				showComparisonReportImg('comparison_ca_image');
				//setMaskHeight(0);
				//alert(1);
				//jQuery("#mask").height(jQuery(document).height());
				changeWaitingMessage();
				saveComparisonReport();
				setTimeout("redirectToComparisonReport()",comparisionReportGenerationTime);
				return false;
			}else{
				//document.getElementById("errorDivAnalysis").innerHTML += "(Comparision Website)";
				return false; // if comparision domainName is invalid
			}
			

	}else{
		return false;
	}			
}

/******   Submitting form with comparision website end here  *****/

// show report generation waiting messages
var wait_msg_count = 0;
var wait_msgs = new Array();
wait_msgs[0] = "Reach Analysis provides insights into your website - instantly!";
wait_msgs[1] = "Reach Analysis helps your online Strategy get better!";
wait_msgs[2] = "Reach Analysis experts help you improve conversion rates and ROI online!";
wait_msgs[3] = "Reach Analysis: SEO, SEM, Social Media Analytics - to make the most of your online efforts!";
wait_msgs[4] = "Reach Analysis is free - like all good things of life!";
function changeWaitingMessage(){
	if(wait_msg_count == 5){
		wait_msg_count = 0;
	}
	var wait_msg_div = document.getElementById("waiting_msg_div");
	var mask = document.getElementById("mask");
	//startWaitMsgFade();
	wait_msg_div.innerHTML = wait_msgs[wait_msg_count];
	wait_msg_count++;
	if(mask.style.display != "none"){
		waitMsgTimeOut = setTimeout("changeWaitingMessage()",5000);
	}
}

//Wait message fade effect
 var w_fadeCount = 0;
 var w_fadeTime = 50;
 var w_fadeTimeInterval = w_fadeTime;
 var w_fadeValueP = 100;
  var w_fadeValue = w_fadeValueP; //400;
function waitMessagefade(){
	if(w_fadeCount < 10) { 
		w_fadeValue += 15;
		w_fadeCount++; 
		document.getElementById("waiting_msg_div").style.color="rgb("+0+","+(w_fadeValue - 80)+","+(w_fadeValue + 5)+")";
		//alert(document.getElementById("waiting_msg_div").style.color);
	}else{
		clearInterval(w_fadeTimeInterval);
		//document.getElementById("waiting_msg_div").style.color = '#09f';
	}
}

function startWaitMsgFade(){
	clearInterval(w_fadeTimeInterval);
	//document.getElementById("waiting_msg_div").style.color = '#09f';
	w_fadeValue = w_fadeValueP;
	w_fadeCount = 0;
	w_fadeTimeInterval = w_fadeTime;
	w_fadeTimeInterval = setInterval("waitMessagefade()",w_fadeTimeInterval);
}

/*function showForgotPassword(){
	document.getElementById("loginDiv").style.display = "none";
	if(sendForgotPwd){
		document.getElementById('forgotContentDiv').innerHTML=sendForgotTxt;
	}
	document.getElementById("forgotContentDiv").style.display = "block";
	return false;
}*/
function hideForgotPassword(){
	document.getElementById("forgotContentDiv").style.display = "none";
	document.getElementById("loginDiv").style.display = "block";
	document.getElementById('errorDiv').innerHTML = "";
	return false;
}

// domain Names focus changes

function domainFocusIn(domainId,defaultValue){
	 var domainName = document.getElementById(domainId);
	 if(domainName.value == defaultValue){
		 domainName.value = '';
	 }
	 domainName.style.color = "#000";
}
function domainFocusOut(domainId,defaultValue){
	 var domainName = document.getElementById(domainId);
	 if(domainName.value == '' || domainName.value == defaultValue){
		 domainName.value = defaultValue;
		 domainName.style.color = "#a7a7a7";
	 }
}
var htmlOriginal="";
function focusIn(id,defaultValue){
	// var documentId = document.getElementById(id);
	 //if(documentId.value == defaultValue){
//		 documentId.value = '';
	// }
	 //documentId.style.color = "#000";
	 //documentId.type="password";
	var documentId = document.getElementById('pwd');
	if(htmlOriginal==''){
		var htmlOriginal = documentId.innerHTML;
	}
	documentId.innerHTML="<input name='password' value='' id='password' class='text_box_mid' style='text-align: center; width:130px; height:17px; *margin-top:1px; ' type='password' onfocus='focusIn(\"password\",\"Password\")' onblur='focusOut(\"password\",\"Password\")'/>";
	 
}
function focusOut(id,defaultValue){
	var documentId = document.getElementById(id);
	 if(documentId.value == '' || documentId.value == defaultValue){
		document.getElementById('pwd').innerHTML="<input name='password' value='Password' id='password' class='text_box_mid' style='text-align: center; width:130px; height:17px; *margin-top:1px;  color: #a7a7a7;' type='text' onfocus='focusIn(\"password\",\"Password\")' onblur='focusOut(\"password\",\"Password\")'/>";
	 }
}
//timer for comparison report generation
var seconds = 30;
var minutes = 0;
function startTimer(){ 
 if(minutes == 0 && seconds == 0){
	redirectToComparisonReport();
	 return;
 }else if (seconds <= 0){ 
    seconds = 60;
    minutes -= 1;
 }
 if(minutes >= 0 && seconds >= 0){
    seconds -= 1 ;
 }
	var minsDisplay = minutes < 10 ? (0 + "" + minutes) : minutes ;
	var secondsDisplay = seconds < 10 ? (0 + "" + seconds) : seconds ;
    document.getElementById("timerDiv").innerHTML = secondsDisplay;
    setTimeout("startTimer()",1000) ;
}

//fade effect start here
var fadeValue = 219; //400;
var blinkStart = true;
var fadeCount = 0; 
	function fade(){
		if(blinkStart){
			blinkStart = false;
			// setting blink effect
			blinkElement('timeOutDiv');
		} 
		if(fadeCount < 6) { 
			fadeValue -= 20;
			fadeCount++; 
			document.getElementById("timeOutDiv").style.display = "block";
			document.getElementById("timeOutDiv").style.color="rgb("+fadeValue+","+0+","+0+")";
			ID = setTimeout("fade()",1500);
		}else{
			hideTimeOutMsg();
		}
	}
	 //hide timeout div
	 function hideTimeOutMsg(){
		 var hideTimeOutDiv = document.getElementById("timeOutDiv");
		 hideTimeOutDiv.innerHTML='';
	 }
// fade effect end here

//blink effect start here
	var g_blinkTime = 800;
	var g_blinkCounter = 0;
	function blinkElement(elementId)
	{
		 if ( (g_blinkCounter % 2) == 0 ){
		  	if ( document.getElementById ){
		   		document.getElementById(elementId).style.visibility = 'visible';
		  	}else if ( document.all ){  // IE 4...
		   		document.all[elementId].style.visibility = 'visible';
		  	}else if ( document.layers ){   // NS 4...
		   		document.layers[elementId].visibility = 'visible';
		  	}
		 }else{
			  if ( document.getElementById ){
			   		document.getElementById(elementId).style.visibility = 'hidden';
			  }else if ( document.all ){  // IE 4...
			   		document.all[elementId].style.visibility = 'hidden';
			  }else if ( document.layers ){   // NS 4...
			   		document.layers[elementId].visibility = 'hidden';
			  }
		 }
		 
		 if ( g_blinkCounter < 1 ){
		  g_blinkCounter++;
		 }else
		 {
		  g_blinkCounter--
		 }
		 setTimeout('blinkElement(\"' + elementId + '\")', g_blinkTime);
	}

//blink effect end here


	//show login page through ajax call
	function showLoginPageThroughAjax(loginDiv){
		var x = Math.random();
		ajaxpage("showLoginPage.do?y="+x,loginDiv);
	}
	
	function showDetailedAnalysisLogin(){
		var id = document.getElementById('loginDiv');
		var forgotDiv = document.getElementById('forgotContentDiv');
		var regResponseText = document.getElementById('regResponseText');
		if(id!='undefined'){
			if(id.style.display=='none'){
				id.innerHTML = '';
				id.style.display='block';
			}
		}
		forgotDiv.style.display = 'none';
		if(regResponseText != null && regResponseText !='undefined'){
			regResponseText.style.display = 'none';
		}
		showLoginPageThroughDetailedAnalysisAjax('loginDiv');
		return false;
	}
	
	function showLoginPageThroughDetailedAnalysisAjax(loginDiv){
		var x = Math.random();
		ajaxpage("showRequestDomainPage.do?tabId=requestDomainScreen&fromPage=homePage&"+x,loginDiv);
	}
	
	//Functions to show and hide the Comprehensive audit image in lightbox
	 function showCompAuditImg(showDivId)
	 {
		var x = Math.random();
		ajaxpage("sampleComprehensiveAuditReport.do?y="+x,showDivId);
		crr = "sca";
			//alert(crr);
		var mask = document.getElementById("mask");
		var caimg = document.getElementById(showDivId);
	 	mask.style.display = "block";
	 	caimg.style.display = "block";
	 	//alert(document.body.clientWidth);
	 	var left = (document.body.clientWidth - 1000)/2+"px";
	 	var top =  (document.body.clientHeight - 500)/2+"px";
	 	caimg.style.left = left;
	 	caimg.style.top = 100+"px";
		setMaskHeight(jQuery("#ca_image").height());
	 }

	 function hideCompAuditImg(showDivId)
	 {
	 var mask = document.getElementById("mask");
	 var caimg = document.getElementById(showDivId);
	 	mask.style.display = "none";
	 	caimg.innerHTML = '';
	 	caimg.style.display = "none";
		setMaskHeight(0);
		setMaskWidth(jQuery(window).width()+20);
	 }
	 
	 // generate quick report pdf through ajax
	function generateQuickReportPdf(){
		var x = Math.random();
		ajaxpage("generateQuickReportPdf.do?y="+x,"quickReportPdfDiv");
	}
	
	function showSocialMediaBuzz(firstId,secondId,firstTabId, secondTabId){
		var secondDocId=document.getElementById(secondId);
		if(secondDocId!='undefined'){
			secondDocId.style.display="none";
			if(document.getElementById(secondTabId)!='undefined'){
			
				document.getElementById(secondTabId).className='';
			}
		}
		var firstDocId = document.getElementById(firstId);
		if(firstDocId!='undefined'){
			firstDocId.style.display="block";
			if(document.getElementById(firstTabId)!='undefined'){
				
				document.getElementById(firstTabId).className='sel';
			}
		}
		
		var dht = jQuery("#tabqr4").height();
		setMaskHeight(dht);
		
	}
	
	//prepares query string for quick report download link
	function downloadQuickReportPdf(link){
		var downloadLink = document.getElementById(link);
		var linkLoc = downloadLink.href;
		// gets domain Name from the span used for quick report title
		var domainName = document.getElementById("raclient").innerHTML;
		linkLoc = linkLoc + "&domainName="+domainName;
		downloadLink.href = linkLoc;
		return true;
	}
	
	/**
	 * Hide feed back popup
	*/
	 function hideFeedbackpopup()
	 {
		jQuery("#mask, #ca_feedback_image").hide();
	 }
	 
	//Functions to show and hide the feedback popup in lightbox
	 function showFeedbackpopup(serviceRequired,domainName)
	  {		
	 	 	//var domainName = '${domainName}';
	 	 	//alert(domainName);
	 		// ajax call to show feed back form
	 		document.getElementById("thankyou_id").innerHTML = '';
	 		var x = Math.random();
	 		var url = "showRaFeedbackForm.do?serviceRequired="+serviceRequired+"&y="+x+"&domainName="+domainName;
	 		ajaxpage(url,'thankyou_id');
	 		//alert(domainName+"-----"+url);
	 		
	  		var left = (jQuery(window).width()-jQuery("#ca_feedback_image").width())/2;
	 		var top = (jQuery(window).height()-jQuery("#ca_feedback_image").height())/2;
	 		//alert(jQuery("#ca_image").height()+"..."+jQuery("#ca_image").width());
	 		jQuery("#ca_feedback_image").css({'top': 50, 'left': left});
	 		jQuery("#mask").css({'position': 'absolute', 'top': 0, 'left': 0, 'width': jQuery(window).width(), 'height':jQuery(document).height()});
	 		//alert('w:'+  jQuery(window).height());
	 		//alert('D:'+ jQuery(document.body).height());
	 		jQuery("#mask, #ca_feedback_image").show();
	 		
	  }
	 
	 /**
	  * submit feed back form
	  * @return
	  */
	function sendFeedbackForm(context) {
	 	var x = Math.random();
	 	ajaxpageform(context+"/raFeedback.do?y="+x,'thankyou_id','feedbackForm');
		document.getElementById('thankyou_id').innerHTML ="<img src='images/busy_1.gif' style='vertical-align:middle' /> Please wait ....";
		//document.getElementById("mandatory_fields_lable").style.display = "none";
	 	return false;
	}
	
	 /**
	  * contact us form
	  * @return
	  */
	function sendContactUsForm(context) {
	 	var x = Math.random();
	 	ajaxpageform(context+"/contactUS.do?y="+x,'thankyou_id','contactUsForm');
		//document.getElementById('thankyou_id').innerHTML ="<img src='images/wait.gif' style='vertical-align:middle' /> Please wait ....";
		//document.getElementById("mandatory_fields_lable").style.display = "none";
	 	return false;
	}
	
	/**
	 * email validation
	*/
	function IsEmailValid(email)
	{
	var EmailOk  = true;
	
	var AtSym    = email.indexOf('@');
	var Period   = email.lastIndexOf('.');
	var Space    = email.indexOf(' ');
	var Length   = email.length - 1 ;  // Array is from 0 to length-1
	 
	if ((AtSym < 1) ||                     // '@' cannot be in first position
	    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	    (Period == Length ) ||             // Must be atleast one valid char after '.'
	    (Space  != -1))                    // No empty spaces permitted
	   {  
	      EmailOk = false;
	   }
	return EmailOk;
	}
	

	function showContactInfo(){
		var x = Math.random();
		ajaxpage("showContactInfo.do?y="+x,'contactInfo');
	}
	function showEditContactInfo(){
		var x = Math.random();
		ajaxpage("showEditContactInfo.do?y="+x,'contactInfo');
	}
	function editContactInfo(){
		var x = Math.random();
		ajaxpageform("editContactInfo.do?y="+x,'contactInfo','registrationForm');
	}
	
	/**
	* This function sets the select box selected value
	* @arguments
	*selectBoxId : select box id to populate
	*selectedValue : selected option value 
	*
	*/
	function setSelectBoxSelectedValue(selectBoxId,selectedValue){
		if(selectedValue != ""){
			var selectBox = document.getElementById(selectBoxId);
			for(var i=0; i < selectBox.options.length; i++){
				if(selectBox.options[i].value == selectedValue){
					selectBox.selectedIndex = i;
					break;
				}
			}
		}
	}
	
	 // edit detailed analysis order
	 function editOrder(){
		document.location.href = "editDetailedAnalysis.do";
	}
	 
	 // confirmed detailed report order
	function confirmedOrder(submitButton){
		var x = Math.random();
		submitButton.disabled = true;
		document.getElementById("confirmOrderDivId").innerHTML = "<img src='images/busy.gif' style='vertical-align:middle' /> Processing your request. Please wait...";
		ajaxpage("confirmedDetailReportRequestAjax.do?y="+x,'confirmOrderDivId');
		return false;
	}
	

	/***********************************************
	* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
	* This notice MUST stay intact for legal use
	* Visit http://www.dynamicdrive.com/ for this script and 100s more.
	***********************************************/

	function pausescroller(content, divId, divClass, delay){
	this.content=content //message array content
	this.tickerid=divId //ID of ticker div to display information
	this.delay=delay //Delay between msg change, in miliseconds.
	this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
	this.hiddendivpointer=1 //index of message array for hidden div
	document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
	var scrollerinstance=this
	if (window.addEventListener) //run onload in DOM2 browsers
	window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
	else if (window.attachEvent) //run onload in IE5.5+
	window.attachEvent("onload", function(){scrollerinstance.initialize()})
	else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
	setTimeout(function(){scrollerinstance.initialize()}, 500)
	}

	// -------------------------------------------------------------------
	// initialize()- Initialize scroller method.
	// -Get div objects, set initial positions, start up down animation
	// -------------------------------------------------------------------

	pausescroller.prototype.initialize=function(){
	this.tickerdiv=document.getElementById(this.tickerid)
	this.visiblediv=document.getElementById(this.tickerid+"1")
	this.hiddendiv=document.getElementById(this.tickerid+"2")
	this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
	//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
	this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
	this.getinline(this.visiblediv, this.hiddendiv)
	this.hiddendiv.style.visibility="visible"
	var scrollerinstance=this
	document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
	document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
	if (window.attachEvent) //Clean up loose references in IE
	window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
	setTimeout(function(){scrollerinstance.animateup()}, this.delay)
	}


	// -------------------------------------------------------------------
	// animateup()- Move the two inner divs of the scroller up and in sync
	// -------------------------------------------------------------------

	pausescroller.prototype.animateup=function(){
	var scrollerinstance=this
	if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
	this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
	this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
	setTimeout(function(){scrollerinstance.animateup()}, 50)
	}
	else{
	this.getinline(this.hiddendiv, this.visiblediv)
	this.swapdivs()
	setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
	}
	}

	// -------------------------------------------------------------------
	// swapdivs()- Swap between which is the visible and which is the hidden div
	// -------------------------------------------------------------------

	pausescroller.prototype.swapdivs=function(){
	var tempcontainer=this.visiblediv
	this.visiblediv=this.hiddendiv
	this.hiddendiv=tempcontainer
	}

	pausescroller.prototype.getinline=function(div1, div2){
	div1.style.top=this.visibledivtop+"px"
	div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
	}

	// -------------------------------------------------------------------
	// setmessage()- Populate the hidden div with the next message before it's visible
	// -------------------------------------------------------------------

	pausescroller.prototype.setmessage=function(){
	var scrollerinstance=this
	if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
	setTimeout(function(){scrollerinstance.setmessage()}, 100)
	else{
	var i=this.hiddendivpointer
	var ceiling=this.content.length
	this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
	this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
	this.animateup()
	}
	}

	pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
	if (tickerobj.currentStyle)
	return tickerobj.currentStyle["paddingTop"]
	else if (window.getComputedStyle) //if DOM2
	return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
	else
	return 0
	}

