

//get ads in rotation

function getRotateAds(paths){
	var xurl=paths+"rotateads/ads-ajax.php?xid=ROTATINGADS_76476384rueyu";
	var divspace="DivAdspace";
	
	//process status
	var proc="<center><img src=\""+paths +"images/progress.gif\"><br>Loading ads...</center>";
	document.getElementById(divspace).innerHTML=proc;

	getDataFromServerSearch(xurl,divspace);

}


function bookmark_us(url, title){

if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}


function addBookmarkus(a){

	var title="Best Christian Community Online";
	var url="http://www.lightoflifecm.com";

		
		if (window.sidebar) // firefox
			window.sidebar.addPanel(title, url, "");
		else if(window.opera && window.print){ // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		}

		else if(document.all)// ie
			window.external.AddFavorite(url, title);

}


	function setAsHome(a){

		try{a.style.behavior='url(#default#homepage)';a.setHomePage('http://www.google.com');return;}
		catch(e){}
	

		return true;
	}


	//Redirect Page
	function redirectPage(url){
		document.location.href=url;

	}

	function getIcons(stag,idname){
				var str;
				var docobj;
				var tmpstr;
				var docroot;

					switch(stag){

						case 'bold':{
							starttag="[B]";
							endtag="[/B]";
						break;
						}

						case 'italics':{
							starttag="[I]";
							endtag="[/I]";
						break;
						}

						case 'ul':{
							starttag="[U]";
							endtag="[/U]";
						break;
						}

						case 'hlink':{

							var msg=prompt("Enter URL link with [http://]","");
								
							if(msg!=""){
								starttag="[A LINK='"+msg+"']";
								endtag="[/A]";
							}

						break;
						}



					};


					if(document.selection){

						docroot= document.getElementById(idname);
						
						tmpstr= docroot.value;
						
	 				   	docobj=document.selection.createRange();
						str=docobj.text;

						docroot.value=tmpstr.replace(str,starttag+str+endtag);
						//docroot.focus();

					} else {

						
							
						    var $before;
						    var $after;
						    var $sel;
						    var $str;
							
							$str = document.getElementById(idname);

   						 	$before= $str.value.substring(0, $str.selectionStart);

    							$sel = $str.value.substring($str.selectionStart, $str.selectionEnd);
    							$after = $str.value.substring($str.selectionEnd, $str.value.length);
  
    							$str.value= String.concat($before, starttag, $sel, endtag, $after) 
					}



	}



	//Copy Shipping Information to Payment Info.
	function CopyShippingInfo(){
		
		var lockval;
		var dc=document;

			if(document.getElementsByName('vin_sameship')[0].checked==true){
				lockval=true;

				//First Name
				dc.getElementsByName('vin_fname')[0].value = dc.getElementsByName('vin_Sfname')[0].value;
				
				//Last Name
				dc.getElementsByName('vin_lname')[0].value = dc.getElementsByName('vin_Slname')[0].value;

				//Address 1
				dc.getElementsByName('vin_add1')[0].value = dc.getElementsByName('vin_Sadd1')[0].value;

				//Address 2
				dc.getElementsByName('vin_add2')[0].value = dc.getElementsByName('vin_Sadd2')[0].value;

				//Phone Number
				dc.getElementsByName('vin_pnumber')[0].value = dc.getElementsByName('vin_Spnumber')[0].value;

				//Province/State
				dc.getElementsByName('vin_pstate')[0].value = dc.getElementsByName('vin_Spstate')[0].value;

				//City
				dc.getElementsByName('vin_city')[0].value = dc.getElementsByName('vin_Scity')[0].value;

				//City
				dc.getElementsByName('vin_pzip')[0].value = dc.getElementsByName('vin_Spzip')[0].value;


			} else {
				lockval=false;

			}


				//First Name
				dc.getElementsByName('vin_fname')[0].disabled=lockval;
				
				//Last Name
				dc.getElementsByName('vin_lname')[0].disabled=lockval;

				//Address 1
				dc.getElementsByName('vin_add1')[0].disabled=lockval;

				//Address 2
				dc.getElementsByName('vin_add2')[0].disabled=lockval;

				//Phone Number
				dc.getElementsByName('vin_pnumber')[0].disabled=lockval;

				//Province/State
				dc.getElementsByName('vin_pstate')[0].disabled=lockval;

				//City
				dc.getElementsByName('vin_city')[0].disabled=lockval;

				//City
				dc.getElementsByName('vin_pzip')[0].disabled=lockval;


	}



	
	//selects a submit form for check out 2 page
	function ProcessformCheckOut2(butname){

	  var theForm=document.getElementById("frmform");

		if(butname=="cmdConfirmOrder"){
		 	theForm.action = "confirm-order.php";

		} else {		
		 	theForm.action = "check-out1.php";
		}

  		theForm.submit();

	}



	//add a detail line for items
	function addControls(){



	     //Get row index ID value
	     var ctrlID=document.getElementById("conID").value;

		//Get browser name
		var browName=navigator.appName;
		var mie="Microsoft Internet Explorer";

		/* create spacer div stretch ======================================= */
		var divp1=document.createElement("div");
		divp1.setAttribute("id","divp1"+ctrlID); 
		divp1.setAttribute("style","width:100%;height:40px;"); 

			if(mie==browName){
				divp1.style.cssText="width:100%;height:40px;";
			}

		/* add div to page */
		 document.getElementById("spacerdiv").appendChild(divp1); 
		/* end create spacer div strech =====================================*/
 
		/* clone combo box for color property */
		var col=document.getElementById("mcol").cloneNode(true);
				
			/* assign color attributes */
			col.setAttribute("id","idcolor"+ctrlID); 
			col.setAttribute("name","idcolor"+ctrlID); 

			col.setAttribute("style","float:left;visibility:visible;width:70px" ); 

				if(mie==browName){
					col.style.cssText="float:left;visibility:visible;width:70px";
				}

			/* add combo box to page */
			 document.getElementById("displaycon").appendChild(col);  		
		/* end here, clone combo box for color property */


		/* clone combo box for size property */
			/* clone color combo box */
			var sizes=document.getElementById("msize").cloneNode(true);
			
			/* assign color attributes */
			sizes.setAttribute("id","idsize"+ctrlID); 
			sizes.setAttribute("name","idsize"+ctrlID); 

			sizes.setAttribute("style","float:left;visibility:visible;width:60px" ); 
			
			if(mie==browName){
				sizes.style.cssText="float:left;visibility:visible;width:60px";
	   		}

			/* add combo box to page */
			 document.getElementById("displaycon").appendChild(sizes);  		
		/* end here, clone combo box for size property */


		/* create textbox for quantity */
			var tqty=document.createElement("input");
			
			tqty.setAttribute("type","text");
			tqty.setAttribute("name","idqty"+ctrlID); 

			tqty.setAttribute("id","idqty"+ctrlID); 
			tqty.setAttribute("style","float:left;width:60px;"); 

			if(mie==browName){
				tqty.style.cssText="float:left;width:60px;";
			}

			/* add combo box to page */
			 document.getElementById("displaycon").appendChild(tqty); 

		/* create div as spacer */
			var divp=document.createElement("div");
			
			divp.setAttribute("id","divp"+ctrlID); 
			divp.setAttribute("style","float:left;width:100%;"); 

			if(mie==browName){
				divp.style.cssText="float:left;width:100%;font-size:1px";
			}

			/* add div to page */
			 document.getElementById("displaycon").appendChild(divp); 



		/* increment index value */
		document.getElementById("conID").value= parseInt(ctrlID) + 1;
			

	}


	var lastRowCol="";

	/* on mouse over */
	function rowOver(obj,lastcol, newcol){

		lastRowCol=lastcol;
		obj.style.background=newcol;
		obj.style.color='#FFFFFF';

		return;
		
	}


	/* on mouse out */
	function rowOut(obj){

		obj.style.background=lastRowCol;
		obj.style.color='#000000';

		return;
	}


	/* get all selected index ID from the list */
	function getSelectedIDs(itemIDs){
		
		var chkIDs="";

		for(i=0;i<itemIDs.length;i++){
			if(document.getElementById("chk"+itemIDs[i]).checked){
				chkIDs+=itemIDs[i]+",";
			} 	
		}
					
		chkIDs=chkIDs.substring(0,chkIDs.length-1);

		return chkIDs;
	}

		/* Delete group of items */
	function chkSelRepost(url,itemIDs){				
	
		var chkID=getSelectedIDs(itemIDs);
		
			if(chkID!=""){
			//alert(chkIDs);
				document.location.href="../cmd.php?id=ASDFKJWE8EyEduadfae7w7e87wryw7e&tid="+chkID+"&p="+url;
				return true;
			}
			else{
				alert("No item(s) selected");														
				return false;
			}
	}



	/* Delete group of items */
	function chkSelDelete(tbl,pkey,url,itemIDs){				
	
	var chkIDs="";
	
		for(i=0;i<itemIDs.length;i++){
			if(document.getElementById("chk"+itemIDs[i]).checked){
				chkIDs+=itemIDs[i]+",";
			} 	
		}
					
		chkIDs=chkIDs.substring(0,chkIDs.length-1);

		
			if(chkIDs!=""){
			//alert(chkIDs);
				document.location.href="../cmd.php?id=453ADFADKNVNCJ&tid="+chkIDs+"&tbl="+tbl+"&pkey="+pkey+"&p="+url;
				return true;
			}
			else{
				alert("No item(s) selected");														
				return false;
			}
	}


	/* login textfield on click event */
	function logfocus(obj,defval){

		if(obj.value==defval){
			obj.value="";
			obj.style.color='#000000';
		}
	}



	/* login textfield on blur event */

	function logblur(obj,defval){

		if(obj.value==""){
			obj.value=defval;
			obj.style.color='#C0C0C0';
		}

	}



//Create Splash window for image details
function popupDivView(objdis,img,height,width){

	var ptr="";


	var cTop=Math.round((document.body.offsetHeight / 2)- (height/2));
	var cLeft=Math.round((document.body.offsetWidth / 2)- (width/2));

	//ptr="<table id=\"spdiv\" style=\"top:"+cTop+"px;left:"+cLeft+"px;height:"+height+";width:"+width+";position:absolute;\">";
	ptr="<table id=\"popupmain\" style=\"top:0px;left:0px;position:absolute;\" width=\"100%\" height=\"100%\" ><tr><td width=\"100%\" height=\"100%\" align=\"center\" valign=\"center\">";

	ptr+="<table id=\"spdiv\" >";
	ptr+="<tr><td id=\"closediv\" onclick=\"document.getElementById('popupmain').style.visibility='hidden';\">Close</td></tr>";

	ptr+="<tr><td id=\"DivDetails\" valign=\"center\" align=\"center\">";
	ptr+="<img src=\"../images/progress.gif\">";	
	ptr+="</td></tr>";	
	ptr+="</table>";

	ptr+="</td></tr></table>";

	objdis.innerHTML=ptr;
	document.getElementById('DivDetails').innerHTML='<img src='+ img +'>';

	//getDataFromServerSearch(url);

}




/* Ajax function ============================== */

function getAjaxObject(){

var xmlhttp;
if (window.XMLHttpRequest)
  {
      // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
      // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
      alert("Your browser does not support XMLHTTP!");
      xmlhttp=null;
  }
    return xmlhttp;

}

/* get random numbers */
function getRandNo(){
    return (Math.random()*1000);    
}

   
function getDataFromServerSearch(url,objname){

    var xmlhttp = getAjaxObject(); 
    var tmpojs="";
    var tmpfld="";        
    var tmpurl=url+"&tid="+ Math.round(getRandNo());
    var objdisp=document.getElementById(objname);

    xmlhttp.open("GET",tmpurl,true);
    xmlhttp.send(null);
        
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4){
            resText=xmlhttp.responseText;            
            objdisp.innerHTML=resText;
	    return true;
			
        }


    };
            
}



/* End Ajax Function here */



