/*************************************************************************************
						This file is copyrighted and should not be used or duplicated
						without the creator's prior notice and approval.
				
						Written Thursday, July 08, 2008
						By:	Cornelius Moore
						Email: cornz24@yahoo.com
***********************************************************************************************/

function C(){}
function X(){
	this.superclass();	
	X.prototype.SetBgColor = function(o,color){o.style.backgroundColor=color;}
	X.prototype.ClearBgColor = function(o){o.style.backgroundColor="";}
	X.prototype.ChgFntColor = function(o,color){o.style.color=color;}
	X.prototype.Cursor = function(o,t){o.style.cursor = t;}
	X.prototype.LoadBlankImg = function(o){o.src = "/images/spacer.gif";}
	X.prototype.MapByAddress  = function(Adr,mapid) {
	var map = new GMap2(document.getElementById(mapid));
	var geocoder = new GClientGeocoder();
	  geocoder.getLatLng(Adr,
		function(point) {
		  if (!point) {
			alert(Adr + " not found");
		  } else {
			//map.addControl(new GOverviewMapControl());
			map.addControl(new GSmallMapControl());
			//map.addControl(new GMapTypeControl());       		
			map.addMapType(G_NORMAL_MAP);
			map.setCenter((point), 15);
			map.addOverlay(new GMarker(point));
			map.openInfoWindowHtml(point,Adr);
		  }
		}
	  );
	}
	X.prototype.SetSelectedIndex = function(o,t){
		//alert(t);
		var d=document.getElementById(o);
		for(var i=0;d.options[i];i++)
			if (d.options[i].text==t)
				d.options[i].selected=true;
	}
	X.prototype.ShowDiv = function(o,idx){
		var g=document.getElementsByTagName("tr");
		var d=document.getElementById(o);
		var tr=document.getElementById("tr_content_"+idx);
		var td=document.getElementById("td_content_"+idx);
				
		/*
		for(var i=0;g[i];i++)
			if (g[i].id && g[i].id.indexOf("div_cnty_")!=-1)
				g[i].style.display="none";
			*/
				
		for(var i=0;g[i];i++)
			if (g[i].id && g[i].id.indexOf("tr_content_")!=-1)
				g[i].style.display="none";
		//d.style.display="block";
		tr.style.display="block";
		td.innerHTML=d.innerHTML;
	}
	X.prototype.ValidateFeedbackFields = function(){
		if(document.getElementById("about").selectedIndex==0){
			alert("What is your feedback about?");
			document.getElementById("about").focus();
			return false;
		}
		if(document.getElementById("feedback").innerHTML.length<10){
			alert("Please please give us your feedback");
			document.getElementById("feedback").focus();
			return false;
		}
		return true;
	}
	X.prototype.ValidateContactFields = function(){
		if(document.getElementById("Sname").value==""){
			alert("Please provide your name");
			document.getElementById("Sname").focus();
			return false;
		}
		if(document.getElementById("Saddress1").value==""){
			alert("Please provide your address");
			document.getElementById("Saddress1").focus();
			return false;
		}
		if(document.getElementById("Scity").value==""){
			alert("What city do you live in?");
			document.getElementById("Scity").focus();
			return false;
		}
		if(document.getElementById("Sstate").selectedIndex==0){
			alert("Please select the state you live in");
			document.getElementById("Sstate").focus();
			return false;
		}
		if(!parseInt(document.getElementById("Szipcode").value)){
			alert("The zipcode you entered is in the wrong format");
			document.getElementById("Szipcode").focus();
			return false;
		}
		if(document.getElementById("Sphone1").value==""){
			alert("What is your phone number?");
			document.getElementById("Sphone1").focus();
			return false;
		}
		if(document.getElementById("Scontent").innerHTML==""){
			alert("Please give us your questions/comments/concerns");
			document.getElementById("Scontent").focus();
			return false;
		}		
		
		return true;
	}
	X.prototype.ValidateLoginFields = function (){
		if(document.getElementById("dstb1").value==""){
			alert("Please enter your username.");
			document.getElementById("dstb1").focus();
			return false;
		}
		if(document.getElementById("dstb2").value==""){
			alert("Please enter your password.");
			document.getElementById("dstb2").focus();
			return false;
		}
		if(document.getElementById("dstb2").value.length<5  || document.getElementById("dstb2").value.length>8){
			alert("Your password must be between 5 to 8 characters long");
			document.getElementById("dstb2").focus();
			return false;
		}
		return true;
	}
	X.prototype.ValidateTrackFields = function (){
		if(!parseInt(document.getElementById("trk1").value)){
			alert("Invalid tracking number. Please try again.");
			document.getElementById("trk1").focus();
			return false;
		}
		if(!parseInt(document.getElementById("trk2").value)){
			alert("Invalid tracking number. Please try again.");
			document.getElementById("trk1").focus();
			return false;
		}
		return true;
	}
	X.prototype.ValidateFields = function(o){
		if(document.getElementById("Sname").value==""){
			alert("Please provide your name");
			document.getElementById("Sname").focus();
			return false;
		}
		if(document.getElementById("Saddress1").value==""){
			alert("Please provide your address");
			document.getElementById("Saddress1").focus();
			return false;
		}
		if(document.getElementById("Scity").value==""){
			alert("What city do you live in?");
			document.getElementById("Scity").focus();
			return false;
		}
		if(document.getElementById("Sstate").selectedIndex==0){
			alert("Please select the state you live in");
			document.getElementById("Sstate").focus();
			return false;
		}
		if(document.getElementById("Sphone1").value==""){
			alert("What is your phone number?");
			document.getElementById("Sphone1").focus();
			return false;
		}
		if(document.getElementById("Scontent").innerHTML==""){
			alert("Please provide a summary of contents \nin the package you are shipping");
			document.getElementById("Scontent").focus();
			return false;
		}
		if(document.getElementById("Rname").value==""){
			alert("Please provide the name of the recipient");
			document.getElementById("Rname").focus();
			return false;
		}
		if(document.getElementById("Raddress").innerHTML==""){
			alert("Please provide the recipient's address");
			document.getElementById("Raddress").focus();
			return false;
		}
		if(document.getElementById("Rcountry").value==""){
			alert("What city do you live in?");
			document.getElementById("Rcountry").focus();
			return false;
		}
		
		alert("We will now submit your pickup request. \nOur staff will make pickup arrangments or contact if we have any questions.");
		//document.getElementById("TblConfirmation").style.display="block";
		//document.getElementById("TblShippmentRequest").style.display="none";
		
		return true;
	}
	X.prototype.ConfirmDelete=function(o){var a = confirm("Are you sure you want to delete this page?")
	if (a)window.location = "remove_page.php?id="+o;else return false;}
	X.prototype.ConfirmRecpDelete=function(o){var a = confirm("Are you sure you want to delete this recipient?")
	if (a)window.location = "forms/remove_recipient.php?id="+o;else return false;}
	X.prototype.ConfirmAgntDelete=function(o,t){var a = confirm("Are you sure you want to delete this agent?")
	if (a)window.location = "remove_agent.php?id="+o+"&bk="+t;else return false;}
	X.prototype.ConfirmPhotoDelete=function(o,t){var a = confirm("Are you sure you want to delete this photo?")
	if (a)window.location = "remove_photo.php?id="+o+"&bk="+t;else return false;}
	X.prototype.FillRecInfo=function(o){
		var d=document.getElementById(o);
		document.getElementById("Rname").value=document.getElementById(o+"_fname").innerHTML+" "+document.getElementById(o+"_lname").innerHTML;
		document.getElementById("Raddress").value=document.getElementById(o+"_addr").innerHTML+"\n"+document.getElementById(o+"_city").innerHTML+" "+document.getElementById(o+"_state").innerHTML+" "+document.getElementById(o+"_zip").innerHTML;		
		document.getElementById("Rcountry").value=document.getElementById(o+"_country").innerHTML;
		//alert(o);
	}
	X.prototype.CountryDgrd = function(val){
		var cols=4;	
		var tty=val.split("&&");
		var d=document.getElementById("IdCountries");
		var tr="";td="";var r="";var c=0;m=0;gd=0;var v=tty.length/cols;	
		var t=v+'';
		var new_end=0;	
		var end_pointer=cols;		
		end_pointer++;
		if(t.indexOf(".")!=-1){
			var k=t.split(".");
			c=(parseInt(k[0])+1);
		}else c=t;
		for(var i=0;i<c;i++){
			td="";gd=0,gh="";
			do{
					var gh=tty[m].replace(/ /gi,"_");
					td+="<td align='left' valign='top' class='nmlGryFont box' style='padding-right:15px;padding-left:5px;padding-top:5px;'><a href='javascript:void(0);' class='orglinkactv' onclick=X.ShowDiv('div_cnty_"+gh+"','"+i+"')><img alt='View our agents in "+tty[m]+"' onerror='this.style.display=\"none\";' src='/flags/"+tty[m]+".gif' border='0' /></a><br><a href='javascript:void(0);' class='orglinkactv' onclick=X.ShowDiv('div_cnty_"+gh+"','"+i+"')>"+tty[m]+"</a></td>";
					m++;gd++;
				//}
			}while(m<end_pointer && gd<cols && tty[m]);
			tr+="<tr>"+td+"</tr>";
			tr+="<tr id='tr_content_"+i+"' style='display:none;'><td id='td_content_"+i+"' colspan='"+cols+"'></td></tr>";//the content TR
			end_pointer+=cols;
		}
		d.innerHTML="<table cellpadding='0' cellspacing='0' class='box'>"+tr+"</table>";
		return true;
	}
	X.prototype.PhotosDgrd = function(val){
		var cols=4;		
		var tty=val.split("&&");
		
		var d=document.getElementById("IdPhotos");
		var tr="";td="";var r="";var c=0;m=0;gd=0;var v=tty.length/cols;	
		var t=v+'';
		var new_end=0;	
		var end_pointer=cols;
		if(t.indexOf(".")!=-1){
			var k=t.split(".");
			c=(parseInt(k[0])+1);
		}else c=t;
		for(var i=0;i<c;i++){
			td="";gd=0;
			do{
				var rw=tty[m].split("~");
				var kp=(rw[1])?rw[1].replace(/_/gi," "):"";
				kp=kp.replace(/x4/gi,"`");
				//kp=kp.replace(/\s/gi," ");
				
				var gh=tty[0];//.replace(/ /gi,"_");
				td+="<td align='left' class='nmlGryFont box' style='padding:5px;' width='100' valign='bottom'><a rel='lightbox' title='"+kp+"<br><br><font color=grey class=9pxCpyrghtFontGry>.:: &copy; 2008. Dennis Shipping Co. Inc. All rights Reserved.</font>' href='/photos/"+rw[0]+"' class='orglink'><img src='/photos/"+rw[0]+"' border='0' width='100' onerror='X.LoadBlankImg(this)'/></a></td>";
				m++;gd++;
			}while(m<end_pointer && gd<cols && tty[m]);
			tr+="<tr>"+td+"</tr>";
			end_pointer+=cols;
		}
		d.innerHTML="<table>"+tr+"</table>";
 		return true;
	}
	X.prototype.RecipientsDgrd = function(val){
		var cols=2;		
		var tty=val.split("&&");
		var d=document.getElementById("tdRecipients");
		var tr="";td="";var r="";var c=0;m=0;gd=0;var v=tty.length/cols;	
		var t=v+'';
		var new_end=0;	
		var end_pointer=cols;
		if(t.indexOf(".")!=-1){
			var k=t.split(".");
			c=(parseInt(k[0])+1);
		}else c=t;
		for(var i=0;i<c;i++){
			td="";gd=0;
			do{
				var rw=tty[m].split("x5");
				var kp=rw[2].replace(/_/gi," ");
				kp=kp.replace(/x4/gi,"`");
				
				var ct=rw[7].replace(/_/gi," ");
				
				var gh=tty[0];//.replace(/ /gi,"_");
				td+="<td width='227' class='nrmlBlkFont' valign='top' ><table width='100%' style='border:1px #663399 dashed;' bgcolor='#DDE7DA' border='0' cellspacing='0' cellpadding='0'><tr><td class='12pxBluFont' bgColor='#F4EBDF' style='border-bottom:1px #999999 dashed;padding-left:8px;'>"+rw[0]+" "+rw[1]+"</td><td align='right' bgColor='#F4EBDF' style='border-bottom:1px #999999 dashed;padding-right:5px;'><a class='orglink' onclick='X.ConfirmRecpDelete(\""+rw[8]+"\")' href='javascript:void(0);' title='Delete this recipient'>X</a></td></tr><tr><td colspan='2' style='padding-left:8px;'>"+kp+"<br>"+rw[3]+", "+rw[4]+" "+rw[5]+" "+ct+"</td></tr><tr><td colspan='2' style='padding-left:8px;'><a href='mailto:"+rw[6]+"' class='orglink'>"+rw[6]+"</a></td></tr></table></td>";
				m++;gd++;
			}while(m<end_pointer && gd<cols && tty[m]);
			tr+="<tr>"+td+"</tr>";
			end_pointer+=cols;
		}
		d.innerHTML="<table>"+tr+"</table>";
 		return true;
	}
}
X.prototype = new C();
X.prototype.contructor = X;
X.prototype.superclass = C;
X = new X();
C=new C();
