
root = window.location.href.replace("http://", "").split("/");
root = !root[1]?"http://"+ root[0] +"/":"http://"+ root[0] +"/"+ root[1] +"/";
    

function CheckSignup(form,FType) {
   f = form;

   for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text" && f.elements[i].type!="password"){
           continue;
       }
       t = f.elements[i].value;

           if(t == null || t.length == 0 && f.elements[i].name != "addy1" && f.elements[i].name != "addy2" && f.elements[i].name != "company" && f.elements[i].name != "fax"
           && f.elements[i].name != "tele" && f.elements[i].name != "zip" && f.elements[i].name != "city" ){
               var et = f.elements[i].getAttribute("errortext");
               alert(et);
               f.elements[i].focus();
               return false;
           }

   }

  if(f.pass.value != f.repass.value ){
		var et = f.repasserror.getAttribute("errortext");
        alert(et);
		f.repass.focus();
		return false;
	}
  if (!f.agr.checked)	{
     var et = f.agr.getAttribute("errortext");
           alert(et);
           f.agr.focus();
     return false;
	}

  return true;
}


function checkformEdit(form,FType) {
   f = form;

   for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text"){
           continue;
       }
       t = f.elements[i].value;

           if(t == null || t.length == 0 && f.elements[i].name != "addy1" && f.elements[i].name != "addy2" && f.elements[i].name != "company" && f.elements[i].name != "fax"
           && f.elements[i].name != "tele" && f.elements[i].name != "zip" && f.elements[i].name != "city" ){
               var et = f.elements[i].getAttribute("errortext");
               alert(et);
               f.elements[i].focus();
               return false;
           }

   }

 

  return true;
}

function valid_cc(form) {
   f = form;
   var x_country_tag = form.country_id.value;
   for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text" && f.elements[i].type!="password"){
           continue;
       }
       t = f.elements[i].value;

       if(t == null || t.length == 0 && f.elements[i].name != "x_company" && f.elements[i].name != "Street2"){
           var et = f.elements[i].getAttribute("errortext");
           alert(et);
           f.elements[i].focus();
           return false;
       }
   }
   	if (x_country_tag == 0)
    	{
       alert("You need to pick your country.");
       form.CountryName.focus()
    	 return false;
    	}

return true;
}

function checkform(form) {
   f = form;

   for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text"){
           continue;
       }
       t = f.elements[i].value;


       if(t == null || t.length == 0 ){
               var et = f.elements[i].getAttribute("errortext");
               alert(et);
               f.elements[i].focus();
               return false;
       }
   }
  document.frmMail.hidaction.value="submitform";
  return true;
}

function openWin(URL) {
aWindow=window.open(URL,"New","toolbar=no,width=800,height=640,status=no,scrollbars=1,menubars=no");
}

function CheckNewsForm(form) {
   f = form;

   for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text" && f.elements[i].type!="password"){
           continue;
       }
       t = f.elements[i].value;
       
       if(t == null || t.length == 0){
           var et = f.elements[i].getAttribute("errortext");
           alert(et);
           f.elements[i].focus();
           return false;
       }
   }

    if(f.catid.value == 0){
		var et = f.catid.getAttribute("errortext");
        alert(et);
		f.catid.focus();
		return false;
    }
    if(f.summary.value == 0){
		var et = f.summary.getAttribute("errortext");
        alert(et);
		f.summary.focus();
		return false;
    }
    if(f.full_story.value == 0){
		var et = f.full_story.getAttribute("errortext");
        alert(et);
		f.full_story.focus();
		return false;
    }


  return true;
}

function CheckSponsor(form) {
   f = form;

   for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text"){
           continue;
       }
       t = f.elements[i].value;

       if(t == null || t.length == 0){
           var et = f.elements[i].getAttribute("errortext");
           alert(et);
           f.elements[i].focus();
           return false;
       }
   }

  return true;
}

function RatingCheck(form) {
   f = form;

   var reviewcheck = f.review.value;
  if (reviewcheck == 0)	{
	 var et = f.review.getAttribute("errortext");
      alert(et);
	 f.review.focus();
     return false;
	}
	
	var votevalcheck = f.voteval.value;
  if (votevalcheck == 0)	{
	 var et = f.voteval.getAttribute("errortext");
      alert(et);
	 f.voteval.focus();
     return false;
	}

return true;
}

function Login(){
	 for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text"){
           continue;
       }
       t = f.elements[i].value;

       if(t == null || t.length == 0){
           var et = f.elements[i].getAttribute("errortext");
           alert(et);
           f.elements[i].focus();
           return false;
       }
   }

  return true;
}

function CheckPass(form) {
    f = form;

   for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text" && f.elements[i].type!="password"){
           continue;
       }
       t = f.elements[i].value;
       
       if(t == null || t.length == 0 && f.elements[i].name != "engine" && f.elements[i].name != "drive"){
           var et = f.elements[i].getAttribute("errortext");
           alert(et);
           f.elements[i].focus();
           return false;
       }
   }

}
function Search(){
	document.frmEditSearch.hidaction.value="editSearch";
	document.frmEditSearch.submit();
}
function selectcountryS(){
	document.frmEditSearch.action="edit_search.php";
	document.frmEditSearch.submit();
}


function AddClick(){
	document.spay.submit();
}
function AddClickReset(){
    document.spay.clickqty.value="1";
   document.spay.submit();
}


function confirm_delete() {
	pmbox=confirm("Warning: Are you sure you want to totally delete this?");
	if (pmbox==true) { // Output when OK is clicked
		return;
	} else {
	// Output when Cancel is clicked
	return false;
	}
}

function chFrm(){
	if(	document.frmListing.list_name.value.search(/\S/)==-1) {
		alert('Please provide a List name');
		document.frmListing.list_name.focus();
		return false;
	}
    opener.document.frmdetail.list_name.value = document.frmListing.list_name.value;
    opener.document.frmdetail.hidaction.value = "SaveStory";
	opener.document.frmdetail.submit();
    window.close();
}  


function chFrmU(){
	if(	document.frmListing.list_name.value.search(/\S/)==-1) {
		alert('Please provide a List name');
		document.frmListing.list_name.focus();
		return false;
	}
    opener.document.savesearch.listid.value = document.frmSearchList.listid.value;
    opener.document.frmdetail.list_name.value = document.frmListing.list_name.value;
 opener.document.frmdetail.hidaction.value = "SaveStory";
	opener.document.frmdetail.submit();
    window.close();
}  




function ChkDel(oForm, grpname) {
        var checked = 0, i = 0, chkArray;


        if (typeof oForm.elements[grpname].length == 'undefined'){
            	chkArray = [oForm.elements[grpname]];
    	} else {
            chkArray = oForm.elements[grpname];
            for (i; i < chkArray.length; i++){
        		if (chkArray[i].checked) {
        			checked++;
        		}
            }
        }

    if (checked == 0)
	{
		alert('You need to check an item to be deleted first.');
		chkArray[0].focus();
        	return false;
	}
	else return confirm('Are you sure you want to delete the selected item' + ((checked > 1) ? 's' : '') + '?');
        
}

function checkAll(formName,groupName){
  var g = document.forms[formName].elements[groupName];
  if(g && !g.length){ g = [g];
      for (var i=0;i<g.length;i++) {
        var e = g[i];
    
        if (e.type=='checkbox') {
          e.checked = 1;
        }
      }
   }
}

function uncheckAll(formName,groupName) {
	var g = document.forms[formName].elements[groupName];
  if(g && !g.length){ g = [g];
      for (var i=0;i<g.length;i++) {
        var e = g[i];
    
        if (e.type=='checkbox') {
          e.checked = 0;
        }
      }
  }
}

function change_image(num,pic,wpic,hpic,path){
	document.slide.src=path+pic;
    document.getElementById('pic'+num).style.fontWeight ='bold';
    document.slide.width=wpic;
    document.slide.height=hpic;
}
function callBrochure(id){
	window.open('./printstory.php?nid='+id,'PrintStory','toolbar=0,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,height=630,width=650,top=10,left=10');
}
function callPrint(id){
	window.open('./pgprint.php?q='+id,'Print','toolbar=0,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,height=630,width=650,top=10,left=10');
}
function openSaveStory(id){
 window.open('./openSaveStory.php?nid='+id,'SaveStory','toolbar=0,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,height=300,width=650,top=10,left=10');
}

function sendMail(id,nid){
	window.open('./sendMail.php?uid='+id+'&nid='+nid,'Sendmail','toolbar=0,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,height=420,width=650,top=10,left=10');
}

function sendFriend(nid){
	window.open('./sendFriend.php?nid='+nid,'Sendmail','toolbar=0,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,height=420,width=650,top=10,left=10');
}
function sendSearchFriend(q){
	window.open('./sendFriend.php?q='+q,'Sendmail','toolbar=0,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,height=420,width=650,top=10,left=10');
}
function send(){
	if(	document.frmContact.fname.value.search(/\S/)==-1) {
		alert('Please provide your first name');
		document.frmContact.fname.focus();
		return false;
	}
	if(	document.frmContact.lname.value.search(/\S/)==-1) {
		alert('Please provide your last name');
		document.frmContact.lname.focus();
		return false;
	}
	if((/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z]{2,5}$/).exec(document.frmContact.email.value)==null){
		alert("Please enter a proper email address to login");
		document.frmContact.email.focus();
		return false;
	}
	document.frmContact.pageaction.value="submitform";
	document.frmContact.submit();	
}

function openWindow(obj,wd,ht){

	features = "width="+wd+",height="+ht;      
	features += ",left=10,top=10,screenX=0,screenY=0,location=no,toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no";
	webwindow=window.open(obj, 'webwindow1', features);
	if (parseInt(navigator.appVersion) >= 4) { 
		webwindow.window.focus(); 
	}
}

function notify() {
	pmbox=confirm("Warning: Are you sure you really want to delete this item?");
	if (pmbox==true) { // Output when OK is clicked
		return;
	} else {
	// Output when Cancel is clicked
	return false;
	}
}



