$(document).ready(function()
{ 
	document.getElementById("load").style.display="none";
	
	footerCopyright(); // to set footer copyright text
	
});

function fun_signup()
{	
	if (validate())
	{
	document.getElementById("load").style.display="block";
	var sub_first_name  = document.getElementById("sub_first_name").value;
	var sub_last_name  = document.getElementById("sub_last_name").value;
	var sub_email  = document.getElementById("sub_email").value;
	var value = sub_first_name+"|*|"+sub_last_name+"|*|"+sub_email;
	var name = "datas";
	var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	var url ="../resources/newsletter.html";
	window.location = url;
	}
}


function fun_signup_outer()
{		
	if (validate())
	{
		document.getElementById("load").style.display="block";
		var sub_first_name  = document.getElementById("sub_first_name").value;
		var sub_last_name  = document.getElementById("sub_last_name").value;
		var sub_email  = document.getElementById("sub_email").value;
		var value = sub_first_name+"|*|"+sub_last_name+"|*|"+sub_email;
		var name = "datas";
		var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		var url ="resources/newsletter.html";
		window.location = url; 
	}
}



function validate()
{
	var sub_email  = document.getElementById("sub_email").value;
	
	if (sub_email == "")
	{
		alert ("Please Enter Email")
		document.getElementById("sub_email").focus();
		return false;
	}
	
	if (echeck(sub_email)==false)
	{
		document.getElementById("sub_email").value="";
		document.getElementById("sub_email").focus()
		return false
	}
	return true;
}


function echeck(str) 
{
		var str1 = str.toLowerCase();
		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
		 }
		  
		/*var domains=new Array();
		domains[0]="gmail";
		domains[1]="yahoo";
		domains[2]="aol";
		domains[3]="ymail";
		domains[4]="hotmail";
		domains[5]="rediffmail";
		domains[6]="rocketmail";

		var n =domains.length;
		var flag = true;
		for (i=0; i<=n;i++)
		{
			if (str1.indexOf(domains[i]) != "-1")
				{	
					
					flag = false;
				}
			
		}

		if (flag ==  false)
		{
				alert ("Enter Company Email");
				return false;
		}*/
		return true;
	}

function emailvalidate()
{
	var emailID=document.frmSample.txtEmail
	
	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
 }

function clear_form()
{
	document.getElementById("sub_first_name").value = "";
	document.getElementById("sub_last_name").value = "";
	document.getElementById("sub_email").value="";	
}

/* for kampyle **/

var k_push_vars = {
     "display_after": 300,
	"view_percentage": 100,
	"popup_font_color": "#000000",
	"popup_background": "#D4E2F0",
	"header": "Your feedback is important to us!",
	"question": "Would you be willing to give us a short (1 minute) feedback?",
	"footer": "Thank you for helping us improve our website",
	"remind": "Remind me later",
	"remind_font_color": "#3882C3",	
	"yes": "Yes",
	"no": "No",
	"text_direction": "ltr",
	"images_dir": "http://cf.kampyle.com/",
	"yes_background": "#76AC78",
	"no_background": "#8D9B86",
	"site_code": 6096918
}
////// kampyle ends //////

/************ height issue *******/


function set_height()
{
	var left_height = $("#whitetable_left").height();
	var right_height = $("#whitetable_right").height();
	//alert (left_height);
//	alert (right_height);
	var fin_height;
	if (left_height > right_height)
	{
		fin_height = left_height;
	}
	if (left_height < right_height)
	{
		fin_height = right_height;
	}
	if (left_height == right_height)
	{
		fin_height = left_height;
	}
	fin_height = fin_height;

	$("#whitetable_left").attr("height",fin_height);
	$("#whitetable_right").attr("height",fin_height+3);
}
function check_images()
{
	var imagesloaded = allImagesLoaded();
	if (imagesloaded == 1)
	{
		set_height();
	}
	else
	{
		setTimeout("check_images()",2000);
	}
}
/************ */////////



// for checking images //


function check_images_inner()
{
	var imagesloaded = allImagesLoaded();
	if (imagesloaded == 1)
	{
		set_height_inner();
	}
	else
	{
		setTimeout("check_images_inner()",2000);
	}
}

function set_height_inner()
{
	var fin_left_height;
	var right_height;
	/* Right height */
	var heigh_whitetable1 = $("#whitetable1").height();
	var heigh_whitetable_right = $("#whitetable_right").height();
	var final_right_height = parseInt(heigh_whitetable1) + parseInt(19) + parseInt(heigh_whitetable_right);
	var left_height = $("#whitetable_left").height();
	//alert (final_right_height);
	if (left_height > final_right_height)
	{
		fin_left_height = left_height;
	}
	if (left_height < final_right_height)
	{
		fin_left_height = final_right_height;
	}
	if (left_height == final_right_height)
	{
		fin_left_height = final_right_height;
	}

	right_height = heigh_whitetable1 + 19;
	fin_left_height = fin_left_height ;	
	
	var fin_right_height = fin_left_height - right_height;
	
	//alert(fin_left_height);
	//alert(right_height);
	$("#whitetable_left").attr("height",fin_left_height);
	$("#whitetable_right").attr("height",fin_right_height);
}
function allImagesLoaded() 
{
	// return variable
	var imagesloaded = 1;
	// All images are saved in an array called document.images. 
	var images = document.images;
	// Loop through all the images
	for (var i = 0;i<images.length;i++)
	{
		// If the image isnt loaded we set the return varible to 0
		if(images[i].complete == false) 
		{
			imagesloaded = 0;
		}
	}
	// This will return 0 if one or more images are not loaded and 1 if all images are loaded.
	return imagesloaded;
}
		
////  ends here ///////

//For footer Copyright text

function footerCopyright()
{
	$(".footer div span:contains('Copyright')").html('Copyright &copy; 2004 - 2011 Treselle Systems, Inc. All Rights Reserved');
}		
