var loadedobjects="";
var rootdomain="http://"+window.location.hostname
var qstring = "";

var prev_img='';
var step_count=0;
//------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------
function photogallery_func_page_no(val)
{
	var xmlHttp="";
	try
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		var url="photogallery.php?state=change&pn="+val;
		
		//url = url+"&fresh="+new Date().getTime();
		show_status(4,"changing page..");
		xmlHttp.onreadystatechange=function() 
		{ 
			if (xmlHttp.readyState==4)
			{		
				document.getElementById("sp_show").innerHTML = xmlHttp.responseText;
				show_status();
			}
		}

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	catch(exception)
	{
		alert(exception);
	}	
}

function mem_photogallery_func_page_no(val,val2)
{
	var xmlHttp="";
	try
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		var url="mem_photogallery.php?state=change&pn="+val+"&mem_id="+val2;
		
		//url = url+"&fresh="+new Date().getTime();
		show_status(4,"changing page..");
		xmlHttp.onreadystatechange=function() 
		{ 
			if (xmlHttp.readyState==4)
			{		
				document.getElementById("sp_show").innerHTML = xmlHttp.responseText;
				show_status();
			}
		}

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	catch(exception)
	{
		alert(exception);
	}	
}

function netmem_func_page_no(val)
{
	var xmlHttp="";
	try
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		var url="net_mem.php?state=change&pn="+val;
		
		//url = url+"&fresh="+new Date().getTime();
		show_status(4,"changing page..");
		xmlHttp.onreadystatechange=function() 
		{ 
			if (xmlHttp.readyState==4)
			{		
				document.getElementById("sp_show").innerHTML = xmlHttp.responseText;
				show_status();
			}
		}

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	catch(exception)
	{
		alert(exception);
	}	
}
function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function show_status(success, message){
	var status_div=document.getElementById('status_mgs');
	var img_path="images/";
	var status_str='';
	var col='';
		switch (success){
		case 0:			//FAILED
				col = "#e8ef3f";
				img_path = img_path+"error.png";		
				break;
		case 1:			//SUCCESS
				col = "#ee1b24";		
				img_path = img_path+"validate.png";						
				break;
		case 2:			//MESSAGE
				col = "#ee1b24";		
 				img_path = img_path+"invalid.png";		
				break;
		case 3:			//required
				col = "#ee1b24";		
 				img_path = img_path+"required.png";		
				break;
		case 4:			//PROCESS
				col = "e8ef3f";		
 				img_path = img_path+"loading.gif";		
				break;

		default:	//CLEAN
			document.getElementById('status_mgs').style.display='none';
			document.getElementById('sp_status').innerHTML='';
			return;
	}
		status_div.style.display='';
		status_div.style.top=iecompattest().scrollTop+'px';
		var width=Zapatec.Utils.getWindowSize().width;
		status_div.style.left = (width - status_div.offsetWidth)/2;
		document.getElementById('stat_img').src = img_path;
		document.getElementById('sp_status').innerHTML='<span style="color:'+col+'">'+message+'</span>';
		if(success!=4)
			setTimeout("document.getElementById('status_mgs').style.display='none'",5000);
		
}
function getposOffset(what, offsettype){
		return (what.offsetParent)? what[offsettype]+this.getposOffset(what.offsetParent, offsettype) : what[offsettype]
	}
	
function get_plain_value(full_txt){
	if(full_txt=='')
		return '';
		
	full_txt=escape(full_txt);
	return full_txt.replace(RegExp("[+]","g"),'^p^');
}

function send_feedback(){
var ref_form=document.frm_feedback;
if(ref_form.sname.value=='')
	{
		alert("please enter your name");
		ref_form.sname.focus();
		return false;
	}
if(ref_form.company.value=='')
	{
		alert("please enter your company name");
		ref_form.company.focus();
		return false;
	}
if(ref_form.email.value=='')
	{
		alert("please enter your email address");
		ref_form.email.focus();
		return false;
	}
if(!validate_email(ref_form.email.value))
	{
		alert("please enter a valid email");
		ref_form.email.focus();
		return false;
	}
if(ref_form.ph.value=='')
	{
		alert("please enter your phone number");
		ref_form.ph.focus();
		return false;
	}
if(ref_form.subject.value=='')
	{
		alert("please enter subject for your feedback request");
		ref_form.subject.focus();
		return false;
	}
if(ref_form.feedback.value=='')
	{
		alert("Please enter Your feedback or Comments!");
		ref_form.feedback.focus();
		return false;
	}
url="joborder.php?sname="+get_plain_value(ref_form.sname.value);
url+="&company="+get_plain_value(ref_form.company.value);
url+="&email="+get_plain_value(ref_form.email.value);
url+="&ph="+get_plain_value(ref_form.ph.value);
url+="&subject="+get_plain_value(ref_form.subject.value);
url+="&feedback="+get_plain_value(ref_form.feedback.value);
url+="&street="+get_plain_value(ref_form.street.value);
url+="&country="+get_plain_value(ref_form.country.value);
url+="&state="+get_plain_value(ref_form.state.value);
url+="&zip="+get_plain_value(ref_form.zip.value);
url+="&url="+get_plain_value(ref_form.url.value);
url+="&fax="+get_plain_value(ref_form.fax.value);
show_status(4,"Sending your coment");
load_content(url,'sp_show');
return false;
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}

function load_content(url,target,flag){		//flag=true need to load a js
	if(url==''||!url)
		return;
	//alert(url);
	
	var xmlHttp="";
	try
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		//alert(url);
		show_status(4,"loading data ...");
		
		xmlHttp.onreadystatechange=function() 
		{ 
			if (xmlHttp.readyState==4)
			{
				if(xmlHttp.status!=200){
					//alert("Error no = "+ xmlHttp.status);
					show_status(0,'error in communication, error no = '+ xmlHttp.status);
					return;
					}

				document.getElementById(target).innerHTML = xmlHttp.responseText;
				
				if(flag){
					var arr = url.split(".");
						//alert(arr[0]);
							loadobjs(arr[0]+"_java.js",arr[0]+"_setup");
						}
			show_status();
			}
		}
		//alert(url);
		page_no=1;
		Zapatec.Utils.writeCookie("page_no_val",page_no,null, '/');

		xmlHttp.open("GET",url+"&fresh="+new Date().getTime(),true);
		xmlHttp.send(null);
	}
	catch(exception)
	{
		alert(exception);
	}
}

function no_action(){		//default no ection function

}

function loadobjs(){
	
	if (!document.getElementById)
		return;
	for (i=0; i<arguments.length-1; i++){
		var file=arguments[i];
		var fileref="";
		if(loadedobjects.indexOf(file) !=-1){
//			alert("already loaded");		
			eval(arguments[arguments.length-1])();
		}
		else if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
			
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref);
			loadedobjects+=file+" "; //Remember this object as being already added to page
//			alert("executing new function");
			//alert(loadedobjects);
		}
		}
}

function show_image(anchorobj,image_id){
	var subobj=document.getElementById('image_view');
	var ref_div=document.getElementById('sp_show');
	var left_offset=getposOffset(ref_div, "offsetLeft")+((580 - subobj.offsetWidth)/2);	//POSIION THE IMAGE DIV CENTER OF CONTENT DIV
	var top_offset=getposOffset(ref_div, "offsetTop");
	if(prev_img==image_id && subobj.innerHTML!=''){
	    show_div(anchorobj,subobj,left_offset,top_offset);
	}
	else
	{
			prev_img=image_id;
			var xmlHttp="";
				try
				{
					xmlHttp=GetXmlHttpObject();
					if (xmlHttp==null)
					{
					  alert ("Your browser does not support AJAX!");
					  return;
					}
					//loadobjs('search_java.js');
					var url="show_image.php?id="+image_id;
										show_status(4,"loading data ...");
					xmlHttp.onreadystatechange=function() 
					{ 
						if (xmlHttp.readyState==4)
							{
								if(xmlHttp.status!=200){
									//alert("Error no = "+ xmlHttp.status);
									show_status(0,'error in communication, error no = '+ xmlHttp.status);
									return;
									}
							var subobj=document.getElementById('image_view');
							subobj.innerHTML = xmlHttp.responseText;
							show_status();
							show_div(anchorobj,subobj,left_offset,top_offset);
						}
					}
					xmlHttp.open("GET",url+"&fresh="+new Date().getTime(),true);
					xmlHttp.send(null);
				}
				catch(exception)
				{
					alert(exception);
				}		
		}
}

function admin_logout(){
	var xmlHttp="";
	try
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		show_status(4,"loggin out...");
		var url="logout.php?fresh="+new Date().getTime();
		xmlHttp.onreadystatechange=function() 
		{ 
			if (xmlHttp.readyState==4)
			{
				show_status(4,'you have successfully logedout and now redirecting to homepage..');
				setTimeout("change_url()",4000);
			}
		}

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	catch(exception)
	{
		alert(exception);
	}
}

function change_url(){
location.replace('index.php');
}
function show_mem_image(anchorobj,image_id){
	var subobj=document.getElementById('image_view');
	var ref_div=document.getElementById('sp_show');
	var left_offset=getposOffset(ref_div, "offsetLeft")+((580 - subobj.offsetWidth)/2);	//POSIION THE IMAGE DIV CENTER OF CONTENT DIV
	var top_offset=getposOffset(ref_div, "offsetTop");
	if(prev_img==image_id && subobj.innerHTML!=''){
	    show_div(anchorobj,subobj,left_offset,top_offset);
	}
	else
	{
			prev_img=image_id;
			var xmlHttp="";
				try
				{
					xmlHttp=GetXmlHttpObject();
					if (xmlHttp==null)
					{
					  alert ("Your browser does not support AJAX!");
					  return;
					}
					//loadobjs('search_java.js');
					var url="show_mem_image.php?id="+image_id;
										show_status(4,"loading data ...");
					xmlHttp.onreadystatechange=function() 
					{ 
						if (xmlHttp.readyState==4)
							{
								if(xmlHttp.status!=200){
									//alert("Error no = "+ xmlHttp.status);
									show_status(0,'error in communication, error no = '+ xmlHttp.status);
									return;
									}
							var subobj=document.getElementById('image_view');
							subobj.innerHTML = xmlHttp.responseText;
							show_status();
							show_div(anchorobj,subobj,left_offset,top_offset);
						}
					}
					xmlHttp.open("GET",url+"&fresh="+new Date().getTime(),true);
					xmlHttp.send(null);
				}
				catch(exception)
				{
					alert(exception);
				}		
		}
}
function doquery(){				//no action function
return;
}
function show_div(anchorobj, subobj,hor_off,ver_off){
			var horizontaloffset= -5											  //calculate user added horizontal offset
			var verticaloffset= anchorobj.offsetHeight 						   //calculate user added vertical offset	
			
			if (typeof hor_off=="undefined" || hor_off=="")
				subobj.style.left= getposOffset(anchorobj, "offsetLeft") + horizontaloffset + "px"
			else
				subobj.style.left=hor_off;
			if (typeof ver_off=="undefined" || ver_off=="")
				subobj.style.top= getposOffset(anchorobj, "offsetTop")+verticaloffset+"px"
			else
				subobj.style.top=ver_off;
			subobj.style.clip= "rect(0 auto 0 0)";
			subobj.style.visibility="visible"
			subobj.startTime=new Date().getTime()
			subobj.contentheight=parseInt(subobj.offsetHeight)
			//if (typeof window["hidetimer_"+subobj.id]!="undefined") //clear timer that hides drop down box?
				//clearTimeout(window["hidetimer_"+subobj.id])
			slideengine(subobj, "down",500)
	}

	function curveincrement(percent){
		return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
	}


	 function slideengine(obj, direction,glidetime){
		var elapsed=new Date().getTime()-obj.startTime //get time animation has run
		step_count=step_count+1;
		//alert(new Date().getTime()+" - " + obj.startTime);
		if (elapsed<glidetime){ //if time run is less than specified length
			var distancepercent=(direction=="down")? curveincrement(elapsed/glidetime) : 1-curveincrement(elapsed/glidetime)
			var currentclip=(distancepercent*obj.contentheight)+"px"
			obj.style.clip=(direction=="down")? "rect(0 auto "+currentclip+" 0)" : "rect("+currentclip+" auto auto 0)"
			window["glidetimer_"+obj.id]=setTimeout(function(){slideengine(obj, direction,glidetime)}, 10);
		}
		else{ //if animation finished
			obj.style.clip="rect(0 auto auto 0)";
		}
	}