//ltrim function
function ltrim(argvalue) {

  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }

  return argvalue;
}

//rtrim function
function rtrim(argvalue) {

  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }

  return argvalue;
}

//trim function
function trim(argvalue) {
  var tmpstr = ltrim(argvalue);

  return rtrim(tmpstr);

}

//function to check email validation
	function validateEmail(email) {//passing controlas a argument
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email.value)) {
		//alert("Error");
		//email.focus();
		//email.select();
		return false;
	}

	return true;
}

//function to check for number	
function isNumber(inputStr) {
		for( var i=0; i < inputStr.length; i++)
		{
			var oneChar = inputStr.substring(i, i + 1)
			if ((oneChar < "0" || oneChar > "9") && (oneChar!="."))
			{
				return false
				exit
			}
		}
		return true
}

//function to check for Integer
function isInteger(inputStr) {
		for( var i=0; i < inputStr.length; i++)
		{
			var oneChar = inputStr.substring(i, i + 1)
			if ((oneChar < "0" || oneChar > "9"))
			{
				return false
				exit
			}
		}
		return true
}
function isalphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
	else	{
           	 return false;
		  }
 	  }
	 return true;
}


//validate date
function checkDate(day1,month1,year1) {
	if(month1== 1)
	{
	month1="Jan"
	}
	else if(month1== 2)	
	{
	month1="Feb"
	}
	else if(month1== 3)	
	{
	month1="Mar"	
	}
	else if(month1== 4)	
	{
	month1="Apr"	
	}
	else if(month1== 5)	
	{
	month1="May"	
	}
	else if(month1== 6)	
	{
	month1="Jun"	
	}
	else if(month1== 7)	
	{
	month1="Jul"	
	}
	else if(month1== 8)	
	{
	month1="Aug"	
	}
	else if(month1== 9)	
	{
	month1="Sep"	
	}
	else if(month1== 10)	
	{
	month1="Oct"	
	}
	else if(month1== 11)	
	{
	month1="Nov"	
	}
	else if(month1== 12)	
	{
	month1="Dec"	
	}

	var myDateStr = day1 + ' ' + month1 + ' ' + year1;
	//alert(myDateStr)
	var myDate = new Date( myDateStr );
	//alert(myDate)
	var myDate_string = myDate.toString();
	//alert(myDate_string)
	var myDate_array = myDate_string.split( ' ' );
	//alert(myDate_array[1])
	if ( myDate_array[1] != month1 ) {
		 return false;
		 } 
	else {
		return true;
	}
}

function isDate(inputStr)
{
	date_arr=inputStr.split('-');
	if(date_arr.count<2)
	{
		return false;	
	}
	else
	{
		return checkDate(date_arr[1],date_arr[0],date_arr[2]);
	}
	
}

//add no. of days to a date
function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

//Open popup window
function popup_win(filepath,h,w,l,t)
{
	window.open(filepath,'','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,max=no,WIDTH='+w+',HEIGHT='+h+',LEFT='+l+',TOP='+t);
}

//jump to url
function go_url(path) 
{
	top.location=path;
}

//Enable Disable a Control
function EnableDisable(ctrl,stat)
{
var var1;
var1=ctrl + '.disabled=' + stat;
alert(var1);
eval(var1);
}
function showhide(ctrl,stat)
{
	if(document.getElementById(ctrl))
	{
		document.getElementById(ctrl).style.display = stat;
	}
}
function changevisibility(ctrl)
{
		if(document.getElementById(ctrl).style.display == 'none')
		{
			document.getElementById(ctrl).style.display = 'block';
		}
		else
		{
			document.getElementById(ctrl).style.display = 'none';
		}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function changeboxvisibility(ctrl)
{
	if(document.getElementById(ctrl).style.display == 'none')
	{
		document.getElementById(ctrl).style.display = 'block';
		document.getElementById('columnheadid').innerHTML="<a href=\"javascript:changeboxvisibility('boxlists_id');\"><img src=\"images/downarrow.jpg\" alt=\"Show\" border=\"0\" id=\"showboxid\" /></a>&nbsp;<a href=\"javascript:changeboxvisibility('boxlists_id');\" class=\"headlink\">MENUBOX</a>";
	}
	else
	{
		document.getElementById(ctrl).style.display = 'none';
		document.getElementById('columnheadid').innerHTML="<a href=\"javascript:changeboxvisibility('boxlists_id');\"><img src=\"images/leftarrow.jpg\" alt=\"Show\" border=\"0\" id=\"hideboxid\" /></a>&nbsp;<a href=\"javascript:changeboxvisibility('boxlists_id');\" class=\"headlink\">MENUBOX</a>";
	}
}
function changeplaylistvisibility(ctrl)
{
	if(document.getElementById(ctrl).style.display == 'none')
	{
		document.getElementById(ctrl).style.display = 'block';
		document.getElementById('columnplaylistid').innerHTML="<a href=\"javascript:changeplaylistvisibility('playlists_id');\"><img src=\"images/downarrow.jpg\" alt=\"Show\" border=\"0\" id=\"showboxid\" /></a>&nbsp;<a href=\"javascript:changeplaylistvisibility('playlists_id');\" class=\"headlink\">PLAYLIST</a>";
	}
	else
	{
		document.getElementById(ctrl).style.display = 'none';
		document.getElementById('columnplaylistid').innerHTML="<a href=\"javascript:changeplaylistvisibility('playlists_id');\"><img src=\"images/leftarrow.jpg\" alt=\"Show\" border=\"0\" id=\"hideboxid\" /></a>&nbsp;<a href=\"javascript:changeplaylistvisibility('playlists_id');\" class=\"headlink\">PLAYLIST</a>";
	}
}
function changespecialvisibility(ctrl)
{
	if(document.getElementById(ctrl).style.display == 'none')
	{
		document.getElementById(ctrl).style.display = 'block';
		document.getElementById('columnspecialid').innerHTML="<a href=\"javascript:changespecialvisibility('menulists_id');\"><img src=\"images/downarrow.jpg\" alt=\"Show\" border=\"0\" id=\"showboxid\" /></a>&nbsp;<a href=\"javascript:changespecialvisibility('menulists_id');\" class=\"headlink\">SPECIAL/EVENT</a>";
	}
	else
	{
		document.getElementById(ctrl).style.display = 'none';
		document.getElementById('columnspecialid').innerHTML="<a href=\"javascript:changespecialvisibility('menulists_id');\"><img src=\"images/leftarrow.jpg\" alt=\"Show\" border=\"0\" id=\"hideboxid\" /></a>&nbsp;<a href=\"javascript:changespecialvisibility('menulists_id');\" class=\"headlink\">SPECIAL/EVENT</a>";
	}
}
function changecategoryvisibility(ctrl)
{
	if(document.getElementById(ctrl).style.display == 'none')
	{
		document.getElementById(ctrl).style.display = 'block';
		document.getElementById('headcategoryid').innerHTML="<a href=\"javascript:changecategoryvisibility('categorylist_id');\"><img src=\"images/downarrow.jpg\" alt=\"Show\" border=\"0\" id=\"showboxid\" /></a>&nbsp;<a href=\"javascript:changecategoryvisibility('categorylist_id');\" class=\"headlink\">IMAGE CATEGORY</a>";
	}
	else
	{
		document.getElementById(ctrl).style.display = 'none';
		document.getElementById('headcategoryid').innerHTML="<a href=\"javascript:changecategoryvisibility('categorylist_id');\"><img src=\"images/leftarrow.jpg\" alt=\"Show\" border=\"0\" id=\"hideboxid\" /></a>&nbsp;<a href=\"javascript:changecategoryvisibility('categorylist_id');\" class=\"headlink\">IMAGE CATEGORY</a>";
	}
}
function createxmlhttpobject()
{
	var xmlhttp1;	
	if (window.XMLHttpRequest)
  	{
  		xmlhttp1=new XMLHttpRequest();
		return xmlhttp1;
  	}
	else if (window.ActiveXObject)
  	{
  		xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
		return xmlhttp1;
  	}
	else
  	{
  		alert("Your browser does not support XMLHTTP!");
		return false;
  	}
}
function showimagepreview(imgpath,iwidth,iheight)
{
	var postop=PageInfo.getMouseY();
	var posleft=PageInfo.getMouseX();
	
	if(posleft>windowwidth()-iwidth) posleft=windowwidth()-iwidth-25;
	if(postop>windowheight()-iheight) postop=windowheight()-iheight-25;
	if(posleft<0) posleft=20;
	if(postop<0) postop=20;
		
	document.getElementById("imagepreviwer").style.position = 'absolute';
	document.getElementById("imagepreviwer").style.left = posleft + "px";
	document.getElementById("imagepreviwer").style.top = postop + "px";
	
	showhide("imagepreviwer","block");
	divcontent="<table><tr><td><a href=\"javascript:hideimagepreview();\"><img src=\"./images/closedata.jpg\" border=0></a></td></tr><tr><td>";
	ilen = String(imgpath).length;
	ext=imgpath.substring(ilen,ilen-4);
	if(ext.toLowerCase()==".mov" || ext.toLowerCase()=="mpeg" || ext.toLowerCase()==".wmv" || ext.toLowerCase()==".mpg" || ext.toLowerCase()==".mp4" || ext.toLowerCase()==".flv" || ext.toLowerCase()==".avi" || ext.toLowerCase()==".mp3" || ext.toLowerCase()==".wav")
	{
		divcontent = divcontent + "<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\">";
		divcontent = divcontent +	"<param name=\"src\" value=\"" + imgpath + "\"><PARAM name=\"AUTOPLAY\" VALUE=\"true\"><PARAM name=\"CONTROLLER\" VALUE=\"false\"><EMBED  src=\"" + imgpath + "\" AUTOPLAY=\"true\" CONTROLLER=\"false\" LOOP=\"true\" PLUGINSPAGE=\"http://www.apple.com/quicktime/\"></EMBED></object>";
	}
	else if(ext.toLowerCase()==".pdf")
	{
	divcontent = divcontent + "<embed src=\"" + imgpath + "\" width=\"400\" height=\"375\"/><br>";
	divcontent = divcontent + "<center><a href=\"" + imgpath + "\" target=\"_blank\" class=\"btnlink\">Click To View</a></center>";
	}
	else if(ext.toLowerCase()=="html" || ext.toLowerCase()==".htm")
	{
		divcontent = divcontent + "<iframe src=\"" + imgpath + "\" width=\"500\" height=\"375\"/></iframe>";
	}
	else
	{
		divcontent = divcontent + "<img src=\"" + imgpath + "\">";
	}
	divcontent = divcontent +  "</td></tr></table>";
	document.getElementById("imagepreviwer").innerHTML=divcontent;
}
function hideimagepreview()
{
	showhide("imagepreviwer","none");
	if(document.getElementById("blackoverlay")) showhide("blackoverlay","none");
}
function comparedate(date1,date2) // format mm-dd-yyyy
{
		var dt1  = parseInt(date1.substring(3,5),10);
	    var mon1 = parseInt(date1.substring(0,2),10);
    	var yr1  = parseInt(date1.substring(6,10),10);
	    var dt2  = parseInt(date2.substring(3,5),10);
	    var mon2 = parseInt(date2.substring(0,2),10);
	    var yr2  = parseInt(date2.substring(6,10),10);
	    var date1 = new Date(yr1, mon1, dt1);
	    var date2 = new Date(yr2, mon2, dt2); 
		if(date2 < date1)
     	{
	         	return false;
		} 
		return true;
}
function changetime(obj)
{
	hhobj=document.getElementById(obj + "_hh");
	mmobj=document.getElementById(obj + "_mm");
	ampmobj=document.getElementById(obj + "_ampm");
	hhval=hhobj.options[hhobj.selectedIndex].value;
	mmval=mmobj.options[mmobj.selectedIndex].value;
	ampmval=ampmobj.options[ampmobj.selectedIndex].value;
	if(ampmval=="PM" && hhval<12) hhval=parseInt(hhval) + 12;
	if(ampmval=="AM" && hhval==12) hhval=parseInt(hhval) - 12;
	if(hhval.length<=1) hhval="0" + hhval;
	if(mmval.length<=1) mmval="0" + mmval;
	document.getElementById(obj).value=hhval + ":" + mmval + ":00";
}
function imageinmenubox(imageid)
{
	var xmlhttp;	
	xmlhttp=createxmlhttpobject();
	if(xmlhttp==false) return;
	var params = "datatype=imageinmenubox&imageid=" + imageid; 
	xmlhttp.open("POST","image_ops.php",true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=function()
  	{
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				document.getElementById("imagepreviwer").style.position = 'absolute';
				document.getElementById("imagepreviwer").style.left = PageInfo.getMouseX() + "px";
				document.getElementById("imagepreviwer").style.top = PageInfo.getMouseY() + "px";
				document.getElementById("imagepreviwer").innerHTML = xmlhttp.responseText;
				showhide("imagepreviwer","block");
			}
	}
	xmlhttp.send(params);
}
function windowwidth()
{
	var myWidth = 0;
 	 if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
   }
  return myWidth;
 }
 function windowheight()
 {
 		var myHeight = 0;
  		if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
    	myHeight = window.innerHeight;
  		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    			//IE 6+ in 'standards compliant mode'
    		   myHeight = document.documentElement.clientHeight;
  		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
     myHeight = document.body.clientHeight;
  }
  	return myHeight;
}
function togglepanel(divid)
{
	if(document.getElementById(divid).style.display!='none')
	{
		document.getElementById(divid + "image").src="images/leftarrow.jpg";
		showhide(divid,'none');
	}
	else
	{
		document.getElementById(divid + "image").src="images/downarrow.jpg";	
		showhide(divid,'block');
	}
}
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
   } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY + 50;
}
function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}
function isneverexpired(cboxid,edate)
{
		if(cboxid.checked)
		{
			edate.style.display='none';
		}
		else
		{
			edate.style.display='block';
		}
}
function checkuserexists(wboxid)
{
	//alert(wboxid);
	if(document.getElementById("profile_user").value=="")
	{
		document.getElementById("useravail").innerHTML="Missing Web Profile";
		showhide("useravail","block");
		return;
	}
	if(!isalphanumeric(trim(document.getElementById("profile_user").value)))
	{
		document.getElementById("useravail").innerHTML="Invalid Profile Name - Only allow alphanumeric value";
		showhide("useravail","block");
		return;
	}
	var xmlhttp;	
	xmlhttp=createxmlhttpobject();
	if(xmlhttp==false) return;
	var params = "datatype=validateuser&bid=" + wboxid + "&userid=" + document.getElementById("profile_user").value + "&optype=" + document.getElementById("optype").value;
	//alert(wboxid);
	xmlhttp.open("POST","validateuser.php",true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=function()
  	{
  		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById("useravail_td").innerHTML=xmlhttp.responseText;
			showhide("useravail","block");
		}
	}
	xmlhttp.send(params);
	
}
