function keyup(what) 
{
  var str = new String(what.value);
  var len = str.length;
  if(len >140)
  {
	  alert("140 characters max only please");
	  what.value=str.substring(0,140);
  }
}
//=============Check if the start value is 9 in mobile code validation ========================
function foundstdcode(param)
{	
	temp = new String(param);phone = temp.substr(0,1);
	if(phone==9) // || phone==9)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//=============Checks if there is any digital value present ========================
function containsdigit(param)
{
	mystrLen = param.length;
	for(i=0;i<mystrLen;i++)
	{
		if((param.charAt(i)=="0") || (param.charAt(i)=="1") || (param.charAt(i)=="2") || (param.charAt(i)=="3") || (param.charAt(i)=="4") || (param.charAt(i)=="5") || (param.charAt(i)=="6") || (param.charAt(i)=="7") || (param.charAt(i)=="8") || (param.charAt(i)=="9"))
		{
			return true;
		}
	}
	return false;
}
//================== Checks for the special characters entry =======================
function specialchar(param)
{
	mystrLen = param.length;
	for(i=0;i<mystrLen;i++)
	{
		if((param.charAt(i)==".") || (param.charAt(i)==" ") || (param.charAt(i)=="'"))
		{
			return true;
		}
	}
	return false;
}
//============= Checks if the email is valid =========================
function validateemailv2(email)
{
	// a very simple email validation checking.
	// you can add more complex email checking if it helps
	var splitted = email.match("^(.+)@(.+)$");
	if(splitted == null) return false;
	if(splitted[1] != null )
	{
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
		if(splitted[1].match(regexp_user) == null) return false;
	}
	if(splitted[2] != null)
	{
		var regexp_domain=/^[\w-\.]*\.[a-za-z]{2,4}$/;
		if(splitted[2].match(regexp_domain) == null)
		{
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null) return false;
		}
		return true;
	}
	return false;
}
//============= checks if there is any alphabet present ========================
function containsalph(param)
{
	mystrLen = param.length;
	for(i=0;i<mystrLen;i++)
	{
		if((param.charAt(i)<"0")||(param.charAt(i)>"9"))
		{
			return true;
		}
	}
	return false;
}
//================= Removes the addedocument.getElementById("toname_org").valued spaces =======================================
function Trim(strValue) 
{
	var j=strValue.length-1;i=0;
	while(strValue.charAt(i++)==' ');
	while(strValue.charAt(j--)==' ');
	return strValue.substr(--i,++j-i+1);
}
function submitform()
{
	//Form.submit();
	//alert(document.getElementById("filenm").value);
	
	if( (document.getElementById("toname_org").value=="")||(document.getElementById("toname_org").value=="Name")||!isNaN(document.getElementById("toname_org").value))
	{
		alert("Please enter your to name!");
		return false;
	}
	else if(containsdigit(document.getElementById("toname_org").value)==true)
	{
		alert("To Name contains numbers!");
		return false;
	}
	else if(document.getElementById("toemail_org").value=='')
	{
		alert("Please enter To Email Id!");
		return false;
	}
	else if( (document.getElementById("toemail_org").value!='') && (validateemailv2(document.getElementById("toemail_org").value)==false) )
	{
		alert("Please enter valid To Email Id!");
		return false;
	}
	else if( (document.getElementById("fromname_org").value=="")||(document.getElementById("fromname_org").value=="Name")||!isNaN(document.getElementById("fromname_org").value))
	{
		alert("Please enter your from name!");
		return false;
	}
	else if(containsdigit(document.getElementById("fromname_org").value)==true)
	{
		alert("From Name contains numbers!");
		return false;
	}
	else if(document.getElementById("fromemail_org").value=='')
	{
		alert("Please enter From Email Id!");
		return false;
	}
	else if( (document.getElementById("fromemail_org").value!='') && (validateemailv2(document.getElementById("fromemail_org").value)==false) )
	{
		alert("Please enter valid From Email Id!");
		return false;
	}
	else if(document.getElementById("filenm").value.length<=0)
	{
		alert("Please upload you .jpg or .gif image!");
		return false;
	}
	else if(document.getElementById("filenm").value.length>0)
	{
		var nmarr = document.getElementById("filenm").value.split(".");
		if(nmarr[1]!="gif" && nmarr[1]!="jpg" && nmarr[1]!="jpeg" )
		{
			alert("Please upload only .jpg or .gif images!");
			return false;
		}
		else
		{	
			document.tmp1.submit();
		}
	}
	else 
	{
		document.tmp1.submit();
	}
}
function updateCoords(c)
{
	jQuery('#x').val(c.x);
	jQuery('#y').val(c.y);
	jQuery('#w').val(c.w);
	jQuery('#h').val(c.h);
};

function checkCoords()
{
	if (parseInt(jQuery('#x').val())) return true;
	alert('Please select a crop region then press submit.');
	return false;
};

function showPreview(coords)
{
	var rx = 150 / coords.w;
	var ry = 150 / coords.h;

	jQuery('#preview').css({
		width: Math.round(rx * 500) + 'px',
		height: Math.round(ry * 370) + 'px',
		marginLeft: '-' + Math.round(rx * coords.x) + 'px',
		marginTop: '-' + Math.round(ry * coords.y) + 'px'
	});
	updateCoords(coords);
}

function setPtrs(x1,y1,w1,h1)
{
	document.getElementById("x").value=x1;
	document.getElementById("y").value=y1;
	document.getElementById("w").value=w1;
	document.getElementById("h").value=h1;
	document.photocrop.submit();
}
function getCroper()
{
	var imgnm=document.getElementById("fileupload_name").value;
	if(imgnm.value = "")
	{
		alert("Failed to upload the image"); return false;
	}
	document.getElementById("toname_tmp").value=document.getElementById("toname_org").value;
	document.getElementById("toemail_tmp").value=document.getElementById("toemail_org").value;
	document.getElementById("fromname_tmp").value=document.getElementById("fromname_org").value;
	document.getElementById("fromemail_tmp").value=document.getElementById("fromemail_org").value;
	document.getElementById("message_tmp").value=document.getElementById("message_org").value;
	
	document.tmp.submit();
}
function getoverlayloader(msg)
{
	aligncenter("lightbox");
	var arrayPageSize = getPageSize();
	//alert(arrayPageSize[1]);
	if(document.getElementById("overlay"))
	document.getElementById("overlay").style.display="block"	;
	//document.getElementById("overlay").style.height=arrayPageSize[1]+"px";
	document.getElementById("overlay").style.height="1600px";

	if(document.getElementById("lightbox"))
	document.getElementById("lightbox").style.display="block"	;
	
	if(document.getElementById("lightbox"))
	document.getElementById("lightbox").innerHTML="<center><br><br><br><br><br><font class=sample11 >"+msg+"Please wait...</font><br><img src='images/ajax-loader.gif' ></center>";
}

function hideoverlayloader()
{
	if(document.getElementById("overlay"))	document.getElementById("overlay").style.display="none"	;
	
	if(document.getElementById("lightbox")) document.getElementById("lightbox").style.display="none"	;
}
function aligncenter(id,id1)
{
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	document.getElementById(id1).style.height = (arrayPageSize[1] + 'px');
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 -  ww) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - ss) / 2);
	
	document.getElementById(id).style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	document.getElementById(id).style.left= (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";	
}
function getXMLHTTPRequest() 
{
	var requester = false;
	try 
	{
		requester = new XMLHttpRequest();
	}
	catch (error) 
	{
		var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHTTP"];
		for(var i = 0; i< aVersions.length;i++)
		{
			try 
			{requester = new ActiveXObject(aVersions[i]);}
			catch (error) 
			{
				continue;
			}
		}
	}
	return requester;
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	


	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function getPageScroll()
{
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function aligncenter(id)
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	//document.getElementById("overlay").style.height = (arrayPageSize[1] + 'px');
	if(document.getElementById(id))
	{
		document.getElementById(id).style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 200) / 2) + 'px');
		document.getElementById(id).style.left = (((arrayPageSize[0] - 20 - 400) / 2) + 'px');	
	}
}
function aligncenter_mod_final(id,ww,ss)
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	//var ww=document.getElementById(id).style.height;
	//var ss=document.getElementById(id).style.width;
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 -  ww) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - ss) / 2);

	document.getElementById(id).style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	document.getElementById(id).style.left= (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";	
	
	//if(document.getElementById(id))
	//{
		//document.getElementById(id).style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 200) / 2) + 'px');
		//document.getElementById(id).style.left = (((arrayPageSize[0] - 20 - 900) / 2) + 'px');	
	//}
}

function close(id)
{
	hideoverlayloader();
	document.getElementById(id).innerHTML='';
}
function aligncenter_mod(id)
{
	if(id== "boxcontactb" || id== "boxcontacta" || id== "boxcontact" )
	{
		ww=100 ; ss=450;	
	}
	if(id== "lightbox")
	{
		ww=460 ; ss=550;	
	}
	if(id== "lightbox_comm")
	{
		ww=400 ; ss=650;	
	}
	if(id == "boxcontacta123")
	{
		ww=460 ; ss=600;	
	}
	if(id == "schoolname")
	{
		ww=434 ; ss=434;	
	}
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	//var ww=document.getElementById(id).style.height;
	//var ss=document.getElementById(id).style.width;
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 -  ww) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - ss) / 2);

	document.getElementById(id).style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	document.getElementById(id).style.left= (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";	
	
	//if(document.getElementById(id))
	//{
		//document.getElementById(id).style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 200) / 2) + 'px');
		//document.getElementById(id).style.left = (((arrayPageSize[0] - 20 - 900) / 2) + 'px');	
	//}
}
function getvideo(idval)
{
	
	var msg="Getting Video Details";
	getoverlayloader(msg);
	var xmlhttp = getXMLHTTPRequest();
	xmlhttp.open('POST', 'getvideo.php', true);     
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4) 
		{
			if (xmlhttp.status == 200) 
			{	
				var resp=xmlhttp.responseText;
				if(resp == "FAIL")
				{
					hideoverlayloader();
					alert("No Such Video Found");
				}
				else
				{
					document.getElementById("lightbox").innerHTML="";
					document.getElementById("lightbox_comm").innerHTML=resp;
					aligncenter_mod("lightbox_comm");
				}
			}
		}
	}
	// Send the POST request
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.send('vid='+idval);	

}
