

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

function openWin(URL) {
aWindow=window.open(URL,"New","toolbar=no,width=800,height=640,status=no,scrollbars=1,menubars=no");
}
function valid_user(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 != "addy2"){
           var et = f.elements[i].getAttribute("errortext");
           alert(et);
           f.elements[i].focus();
           return false;
       }
   }

  var country = f.country.value;
  if (country == 0)	{
	 alert("You must choose an country.");
     return false;
	}


return true;
}

function valid_cc(form) {
   f = form;
   var x_country_tag = form.country.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.country.focus()
    	 return false;
    	}

return true;
}

function valid_store(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 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 openWin(URL) {
    aWindow=window.open(URL,"New","toolbar=no,width=800,height=640,status=no,scrollbars=1,menubars=no");
}
function preview() {


aWindow=window.open(URL,"Preview","toolbar=no,width=400,height=300,status=no,scrollbars=no,resize=no,menubars=no");
}

function checkMaxLength(field, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
}

function isDefaultMessage()  {
    if(document.getElementById('contactform').message.value == document.getElementById('contactform').defaultText.value)  {
		document.getElementById('contactform').message.value = '';
		alert('please enter a message');
        document.getElementById('contactform').message.focus();
        return false;
    } 
    if(document.getElementById('contactform').message.value == '') {
         return false;
    } else {
        return true;
    }

return false;
}

	var ProcessingText = "Send Message";

	var cnt=0;
	function doValidate(f){
		f.Submit.value=ProcessingText;
		f.Submit.disabled=true;
		if (cnt==0)f.submit();
	    	cnt++;
		}

function uncheckAll(obj,field,formName) {
	var ChckBxs = formName.elements[field];
	if(ChckBxs.length!=-1)	{
		for (i = 0; i < ChckBxs.length; i++){
			if(ChckBxs[i].value!="99")
				ChckBxs[i].checked = false ;
		}
	}
}

function fetch_cookie(name)
{
	cookie_name = name + '=';
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length)
	{
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
		{
			var value_end = document.cookie.indexOf (';', value_begin);
			if (value_end == -1)
			{
				value_end = cookie_length;
			}
			return unescape(document.cookie.substring(value_begin, value_end));
		}
		cookie_begin = document.cookie.indexOf(' ', cookie_begin) + 1;
		if (cookie_begin == 0)
		{
			break;
		}
	}
	return null;
}

function set_collapse()
{

    for (i=1; i<4; i++){
        collapsed = fetch_cookie('_collapselinktop'+i);
        if (collapsed){
            document.getElementById('linktop'+i).style.display = "none";
            document.getElementById("collapseimg_linktop" + i).src = 'images/icon_cross.gif';
        }
    }

	return false;
}


function toggle_collapse(objid)
{

	obj = document.getElementById(objid);
	img = document.getElementById("collapseimg_" + objid);
	

    if (obj.style.display == "none")
	{
		var itemcol = '';
        obj.style.display = "";
        img.src = 'images/icon_minus.gif';
        save_collapsed(objid,itemcol,false);

	}
	else
	{
		var itemcol = 'display:none';
        obj.style.display = "none";
        img.src = 'images/icon_cross.gif';
        save_collapsed(objid,itemcol,true);

	}
	return false;
}

function save_collapsed(objid, value,isset)
{
	if (!isset){
	   document.cookie = "_collapse"+ objid + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
	} else {
       expires = new Date();
	   expires.setTime(expires.getTime() + (1000 * 86400 * 365));
       document.cookie = "_collapse"+ objid + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";

    }


}

function new_storecat(form) {
 
  var name_tag = form.CatTitle.value;

    if (!name_tag)
	{
   alert("You forgot to type the name of the category");
	 form.CatTitle.focus()
         return false;
     }

return true;
}

function checkAll(obj, field, formName){
	var ChckBxs = formName.elements[field];
	if(formName.ch_all.checked==true)
		chkd=true;
	else
		chkd=false;
	if(ChckBxs.length>=1)	{
		for (i = 0; i < ChckBxs.length; i++){
			ChckBxs[i].checked = chkd;
		}
	}
	else{
		formName.elements[field].checked = chkd;
	}
}
function addField( area,iclass ) {
       
        if( !document.getElementById ) return ; // Only DOM browsers

        var field_area = document.getElementById( area ) ;
        var lastRow = field_area.rows.length ;
        var iteration = lastRow ;
        var row = field_area.insertRow( lastRow ) ;

        // Cells
        var cellLeft = row.insertCell(0) ;

        var count = lastRow - 1 ;

        // alert('lastRow is '+lastRow+' iteration is '+iteration+' row is '+row+' count is '+count ) ;

        if( count > 7) {alert('You are not allowed anymore upload boxes'); return ;}
       
        if( document.createElement ) { //W3C Dom method.
                var file = document.createElement('input') ;
                //file.style.font ='Tahoma 11px';
                file.style.color ='#797979';
                file.style.width ='220px';
                file.name = 'imageup[]' ;
                file.type = 'file' ;
                cellLeft.appendChild( file ) ;
        }
}

function DistableStore(id) {
	pmbox=confirm("Are you sure you want to Disable this store?");

    if (pmbox==true) { // Output when OK is clicked
    document.location.href='mystore.php?sid='+id;
	} else {
	// Output when Cancel is clicked
	return false;
	}
}
function EnableStore(id) {
	pmbox=confirm("Are you sure you want to Enable this store?");
	if (pmbox==true) { // Output when OK is clicked
		document.location.href='mystore.php?en=1&sid='+id;
	} else {
	// Output when Cancel is clicked
	return false;
	}
}

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 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;
}