function setTab(tab)
{		
	var presentTabs = document.getElementById('tabs').value;
	var tabArray = explode(",",presentTabs);
	var tabCount = tabArray.length;
	var a=0;
	var b=0;
	var checktab = "";
	var tabdiv = "";
	var tabshow = "";
	//alert(presentTabs);
	for(a=0 ; a<tabCount ; a++)
	{
		b = a+1;
		checktab = trim(tabArray[a]);
		if(checktab != "")
		{
			tabdiv = "tab_"+checktab;
			tabshow = "tab"+checktab;
			//alert(tab+" : "+tabdiv);
			
			if(checktab == tab)
			{
				if(b==tabCount)
				{
					document.getElementById(""+tabdiv+"").style.display = "";
				}
				else
				{
					document.getElementById(""+tabdiv+"").style.display = "";
				}
				
				
				var page = tab+".php";
				var update = tabdiv;
				new Ajax.Request(page,   
				{   method:'post',
					onSuccess: function(transport)
					{       
						var response = trim(transport.responseText);
						//alert(response);
						document.getElementById(""+update+"").innerHTML = response;
					} 
				});
				
			}
			else
			{
					if(b==tabCount)
					{
						document.getElementById(""+tabdiv+"").style.display = "none";
					}
					else
					{
						document.getElementById(""+tabdiv+"").style.display = "none";
					}
			}
		}
	}
}

function setDatafeedtype(el)
{
	var val = el.value;
	if(val == "")
	{
		// set xml
		document.getElementById("tr_feedurl").style.display = "none";
		document.getElementById("tr_feedurl2").style.display = "none";
		document.getElementById("tr_feedauth").style.display = "none";
		document.getElementById("tr_feedauth2").style.display = "none";
		document.getElementById("headxml").style.display = "none";
		document.getElementById("headxls").style.display = "none";
		document.getElementById("uploadxls").style.display = "none";
		document.getElementById("uploadxls2").style.display = "none";
	}
	else if(val == 0)
	{
		// set xml
		document.getElementById("tr_feedurl").style.display = "";
		document.getElementById("tr_feedurl2").style.display = "";
		document.getElementById("tr_feedauth").style.display = "";
		document.getElementById("tr_feedauth2").style.display = "";
		document.getElementById("headxml").style.display = "";
		document.getElementById("headxls").style.display = "none";
		document.getElementById("uploadxls").style.display = "none";
		document.getElementById("uploadxls2").style.display = "none";
	}
	else if(val == 1)
	{
		// set xls
		document.getElementById("tr_feedurl").style.display = "";
		document.getElementById("tr_feedurl2").style.display = "";
		document.getElementById("tr_feedauth").style.display = "";
		document.getElementById("tr_feedauth2").style.display = "";
		document.getElementById("headxml").style.display = "none";
		document.getElementById("headxls").style.display = "";
		document.getElementById("uploadxls").style.display = "none";
		document.getElementById("uploadxls2").style.display = "none";
	}
	else if(val == 2)
	{
		// set xls upload
		document.getElementById("tr_feedurl").style.display = "none";
		document.getElementById("tr_feedurl2").style.display = "none";
		document.getElementById("tr_feedauth").style.display = "none";
		document.getElementById("tr_feedauth2").style.display = "none";
		document.getElementById("headxml").style.display = "none";
		document.getElementById("headxls").style.display = "";
		document.getElementById("uploadxls").style.display = "";
		document.getElementById("uploadxls2").style.display = "";
	}
	return true;
}

function isUrl(s) 
{
	var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

var currentcont = "";
function validateSource()
{
	var feedtype = document.getElementById("datafeed_type").value;
	if(feedtype == "")
	{
		alert("You must select a datafeed type!");
		return false;
	}
	if(feedtype != 2)
	{
		var feedurl = document.getElementById("datafeed_url").value;
		if(feedurl == "" || feedurl == "http://www.yourdomain.com/folder/filename.xml or .xls")
		{
			alert("You must enter a valid url for your datafeed!");
			return false;
		}
		if(!isUrl(feedurl))
		{
			alert("You must enter a valid url for your datafeed!");
			return false;
		}
	}
	else
	{
		var feedurl = document.getElementById("xlsdata").value;
	}
	
	if(feedtype != 0)
	{
		var head = document.getElementById("datafeed_xlsheading").value;
		if(head == "")
		{
			alert("You must select how columns names are determined!");
			return false;
		}
	}
	else
	{
		var head = document.getElementById("datafeed_xmltagname").value;
		if(head == "")
		{
			alert("You must select how documents are determined!");
			return false;
		}
		if(head.indexOf("<") >= 0)
		{
			head = head.replace("<","");
		}
		if(head.indexOf(">") >= 0)
		{
			head = head.replace(">","");
		}
		document.getElementById("datafeed_xmltagname").value = head;
	}
	
	if(feedtype == 0 || feedtype == 1)
	{
		var un = document.getElementById("datafeed_username").value;
		var pw = document.getElementById("datafeed_password").value;
	}
	
	currentcont = document.getElementById("trvalidation").innerHTML;
	document.getElementById("trvalidation").innerHTML ="<img src=\"images/loading.gif\" width=\"20\" height=\"20\">";
	//alert(feedtype+" == "+feedurl+" == "+head);
	
	if(feedtype == 0 || feedtype == 1)
	{
		new Ajax.Request('check-datafeed',   
		{   method:'post',
			parameters: {tr_dt: feedtype, tr_du: feedurl,tr_dh:head,tr_un:un,tr_dp:pw},
			onSuccess: function(transport)
			{       
				var response = transport.responseText;
				document.getElementById("trvalidation").innerHTML = currentcont;
				//alert(response);
				
				var poserror = substr(response,0,5);
				if(poserror == "Error")
				{
					alert(response);
					return false;
				}
				else
				{
					document.getElementById("savecontent").value = 1;
					if(document.getElementById("tri").value != "")
					{
						var answer = confirm("Do you want to remap the fields of your file?")
						if (answer){// continue	
						}
						else
						{
							document.getElementById("validatemsg").innerHTML = "<br>Datafeed validated";
							return false;
						}
					}
		
					returnArray = explode("|",response);
					var arcnt = returnArray.length;
					//alert(arcnt);
					var a = "";
					var newselect = "<option value=\"\">-- select field (optional field) --";
					var newselect2 = "<option value=\"\">-- select field (mandatory field) --";
					var newselectrest = "";
					for (a = 0; a < arcnt; a++)
					{
						newselectrest += "<option value=\""+returnArray[a]+"\">"+returnArray[a]+"</option>";
					};
					//alert(newselect2+newselectrest);
					document.getElementById("slt_title").innerHTML = "<select class=\"trform2\" id=\"slt_titleq\"  name=\"slt_title\">"+newselect2+newselectrest+"</select>";
					document.getElementById("slt_url").innerHTML = "<select class=\"trform2\"  id=\"slt_urlq\" name=\"slt_url\">"+newselect2+newselectrest+"</select>";
					document.getElementById("slt_order").innerHTML = "<select class=\"trform2\"  name=\"slt_order\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_text").innerHTML = "<select class=\"trform2\"  name=\"slt_text\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_text2").innerHTML = "<select class=\"trform2\"  name=\"slt_text2\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_price").innerHTML = "<select class=\"trform2\"  name=\"slt_price\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_image").innerHTML = "<select class=\"trform2\"  name=\"slt_image\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_category").innerHTML = "<select class=\"trform2\"  name=\"slt_category\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_brand").innerHTML = "<select class=\"trform2\"  name=\"slt_brand\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_ean").innerHTML = "<select class=\"trform2\"  name=\"slt_ean\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_id").innerHTML = "<select class=\"trform2\"  name=\"slt_id\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_promo").innerHTML = "<select class=\"trform2\"  name=\"slt_promo\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_promotext").innerHTML = "<select class=\"trform2\"  name=\"slt_promotext\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_retail").innerHTML = "<select class=\"trform2\"  name=\"slt_retail\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_stock").innerHTML = "<select class=\"trform2\"  name=\"slt_stock\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_ship").innerHTML = "<select class=\"trform2\"  name=\"slt_ship\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_update").innerHTML = "<select class=\"trform2\"  name=\"slt_update\">"+newselect+newselectrest+"</select>";
					document.getElementById("slt_filetype").innerHTML = "<select class=\"trform2\"  name=\"slt_filetype\">"+newselect+newselectrest+"</select>";
					
					document.getElementById("validatemsg").innerHTML = "<br>Datafeed validated";
				}
			}
		});
	}
	else
	{
		document.getElementById("tr_dh").value = head;
		document.getElementById("tr_dt").value = feedtype;
		document.typeresultForm.submit();
	}
}

function uploadValidated(response)
{
	response = base64_decode(response);
	document.getElementById("trvalidation").innerHTML = currentcont;
	
	var poserror = substr(response,0,5);
	if(poserror == "Error")
	{
		alert(response);
		return false;
	}
	else
	{
		document.getElementById("savecontent").value = 1;
		if(document.getElementById("tri").value != "")
		{
			var answer = confirm("Do you want to remap the fields of your file?")
			if (answer){// continue	
			}
			else
			{
				document.getElementById("validatemsg").innerHTML = "<br>Datafeed validated";
				return false;
			}
		}
	
		returnArray = explode("|",response);
		
		var arcnt = returnArray.length;
		//alert(arcnt);
		var a = "";
		var newselect = "<option value=\"\">-- select field (optional field) --";
		var newselect2 = "<option value=\"\">-- select field (mandatory field) --";
		var newselectrest = "";
		for (a = 0; a < arcnt; a++)
		{
			newselectrest += "<option value=\""+returnArray[a]+"\">"+returnArray[a]+"</option>";
		};
		document.getElementById("slt_title").innerHTML = "<select class=\"trform2\"  id=\"slt_titleq\" name=\"slt_title\">"+newselect2+newselectrest+"</select>";
		document.getElementById("slt_url").innerHTML = "<select class=\"trform2\" id=\"slt_urlq\" name=\"slt_url\">"+newselect2+newselectrest+"</select>";
		document.getElementById("slt_order").innerHTML = "<select class=\"trform2\" name=\"slt_order\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_text").innerHTML = "<select class=\"trform2\"  name=\"slt_text\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_text2").innerHTML = "<select class=\"trform2\"  name=\"slt_text2\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_price").innerHTML = "<select class=\"trform2\"  name=\"slt_price\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_image").innerHTML = "<select class=\"trform2\"  name=\"slt_image\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_category").innerHTML = "<select class=\"trform2\"  name=\"slt_category\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_brand").innerHTML = "<select class=\"trform2\"  name=\"slt_brand\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_ean").innerHTML = "<select class=\"trform2\"  name=\"slt_ean\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_id").innerHTML = "<select class=\"trform2\"  name=\"slt_id\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_promo").innerHTML = "<select class=\"trform2\"  name=\"slt_promo\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_promotext").innerHTML = "<select class=\"trform2\"  name=\"slt_promotext\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_retail").innerHTML = "<select class=\"trform2\"  name=\"slt_retail\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_stock").innerHTML = "<select class=\"trform2\"  name=\"slt_stock\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_ship").innerHTML = "<select class=\"trform2\"  name=\"slt_ship\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_update").innerHTML = "<select class=\"trform2\"  name=\"slt_update\">"+newselect+newselectrest+"</select>";
		document.getElementById("slt_filetype").innerHTML = "<select class=\"trform2\"  name=\"slt_filetype\">"+newselect+newselectrest+"</select>";
		
		document.getElementById("validatemsg").innerHTML = "<br>Datafeed validated";
	}
}

var divexshown = "";
function showExample(img,div, el)
{
	if(el != divexshown && divexshown != "")
	{
		divexshown.style.border = "1px solid #FFFFFF";
	}
	divexshown = el;
	
	var showhtml = "<div style=\"text-align:right;\"><a href=\"javascript:hideExample('"+div+"')\">close preview <img src=\"images/close.png\" border=\"0\" style=\"position:relative;top:2px;\"></a>&nbsp;</div><div style=\"width:320px;height:420px;\"><img src=\"images/"+img+"\"></div></div>";
	document.getElementById(""+div+"").innerHTML = showhtml;
	openshowdiv = div;
	document.getElementById(""+div+"").style.display = "";
	el.style.border = "1px solid #C9C9C9";
}

function hideExample(div)
{
	document.getElementById(""+div+"").innerHTML = "";
	document.getElementById(""+div+"").style.display = "none";
	divexshown.style.border = "1px solid #FFFFFF";
}

function setTemplateHTML(tno)
{
	if(document.getElementById("templatecode").value != "")
	{
		var answer = confirm("The current template is not empty. Do you want to overwrite?")
		if (answer){// continue	
		}
		else
		{
			return false;
		}
	}
	
	var page = "template"+tno+".php";
	new Ajax.Request(page,   
	{   method:'post',
		onSuccess: function(transport)
		{       
			var response = transport.responseText;
			//alert(response);
			document.getElementById("templatecode").value = response;
			return true;
		} 
	});

}

function saveTypeResult(trtype)
{
	if(trtype == "1")
	{
		document.typeresultForm.target = "uploadFrame";
		document.typeresultForm.action = "save-tr";
		
		var feedtype = document.getElementById("datafeed_type").value;
		if(feedtype == "")
		{
			alert("You must select a datafeed type!");
			return false;
		}
		if(feedtype != 2)
		{
			var feedurl = document.getElementById("datafeed_url").value;
			if(feedurl == "" || feedurl == "http://www.yourdomain.com/folder/filename.xml or .xls")
			{
				alert("You must enter a valid url for your datafeed!");
				return false;
			}
			if(!isUrl(feedurl))
			{
				alert("You must enter a valid url for your datafeed!");
				return false;
			}
		}
		else
		{
			var feedurl = document.getElementById("xlsdata").value;
		}
		
		if(feedtype != 0)
		{
			var head = document.getElementById("datafeed_xlsheading").value;
			if(head == "")
			{
				alert("You must select how columns names are determined!");
				return false;
			}
		}
		else
		{
			var head = document.getElementById("datafeed_xmltagname").value;
			if(head == "")
			{
				alert("You must select how documents are determined!");
				return false;
			}
			if(head.indexOf("<") >= 0)
			{
				head = head.replace("<","");
			}
			if(head.indexOf(">") >= 0)
			{
				head = head.replace(">","");
			}
			document.getElementById("datafeed_xmltagname").value = head;
		}
		
		var titleselect = document.getElementById("slt_titleq").value;
		//alert(titleselect);
		if(titleselect == "")
		{
			alert("You must map your title field to our title field!");
			return false;
		}
		
		var urlselect = document.getElementById("slt_urlq").value;
		if(urlselect == "")
		{
			alert("You must map your url field to our url field!");
			return false;
		}
		
		// save the result
		document.getElementById("tr_dh").value = head;
		document.typeresultForm.target = "_top";
		document.typeresultForm.action = "save-tr";
	}
	else if(trtype == "2")
	{
		var templatecode = 	document.getElementById("templatecode").value;
		if(templatecode == "")
		{
			alert("You must create a template");
			return false;
		}
	}
	
	document.typeresultForm.submit();
}

function clicksee()
{
	document.getElementById("clickseeimg").style.display = "none";
	document.getElementById("clicksee").style.backgroundImage = "url(images/clickseebg.jpg)";
	document.getElementById("clicksee").innerHTML = "<input type=\"text\" value=\"type here\" onfocus=\"if(this.value==&#039;type here&#039;){this.value=&#039;&#039;;}\" id=\"q\" name=\"q\" onKeyUp=\"getTypeResult(this)\" autocomplete=off style=\"width:150px;position:relative;left:260px;top:76px;font-size:10px;color:red;\"><div id=\"divtyperesult\" style=\"width:300px;height:400px;overflow:auto;position:relative;left:120px;top:76px;\"></div>";
}

function setPrice(val,per)
{
	if(per == "y")
	{
		document.getElementById("a3").value = val;
		document.getElementById("t3").value = "Y";
		document.getElementById("pricepaid").innerHTML = val+" per year";
	}
	else
	{
		document.getElementById("a3").value = val;
		document.getElementById("t3").value = "M";
		document.getElementById("pricepaid").innerHTML = val+" per month";
	}
}

function checkSignup()
{
	// check username
	var username = document.getElementById("user_login");
	if(!validateInput('req',username,'Enter an username.')){return false;} 
	if(!validateInput('minlen=5',username,'Your an username should be at least 5 characters.')){return false;} 
	if(!validateInput('maxlen=50',username,'Your an username can be 50 characters at most.')){return false;} 
	
	// check email
	var email = document.getElementById("user_email");
	if(!validateInput('req',email,'Enter your e-mail address.')){return false;} 
	if(!validateInput('minlen=5',email,'Your e-mail address should be at least 5 characters.')){return false;} 
	if(!validateInput('maxlen=50',email,'Your e-mail address can be 50 characters at most.')){return false;} 
	if(!validateInput('email',email,'The e-mail address you entered is invalid.')){return false;} 
	
	// check first name
	var firstname = document.getElementById("name");
	if(!validateInput('req',firstname,'Enter a first name.')){return false;} 
	if(!validateInput('minlen=2',firstname,'Your first name should be at least 2 characters.')){return false;} 
	if(!validateInput('maxlen=25',firstname,'Your first name can be 25 characters at most.')){return false;} 
	if(!validateInput('alnum_s',firstname,'Your first name can consist of letters, numbers and spaces only.')){return false;}  
	
	// check last name
	var lastname = document.getElementById("lastname");
	if(!validateInput('req',lastname,'Enter a last name.')){return false;} 
	if(!validateInput('minlen=2',lastname,'Your last name should be at least 2 characters.')){return false;} 
	if(!validateInput('maxlen=25',lastname,'Your last name can be 25 characters at most.')){return false;} 
	if(!validateInput('alnum_s',lastname,'Your last name can consist of letters, numbers and spaces only.')){return false;}  
	
	// check company
	var companyname = document.getElementById("companyname");
	if(!validateInput('req',companyname,'Enter a company name.')){return false;} 
	if(!validateInput('minlen=2',companyname,'Your company name should be at least 2 characters.')){return false;} 
	if(!validateInput('maxlen=25',companyname,'Your company name can be 25 characters at most.')){return false;} 
	if(!validateInput('alnum_s',companyname,'Your company name can consist of letters, numbers, dots and spaces only.')){return false;}  
	
	// check country
	var country = document.getElementById("country");
	if(!validateInput('req',country,'Select a country.')){return false;} 
	
	// check password 1 + 2
	var pass1 = document.getElementById("pass1");
	if(!validateInput('req',pass1,'Enter a password.')){return false;} 
	if(!validateInput('minlen=5',pass1,'Your password should be at least 5 characters.')){return false;} 
	if(!validateInput('maxlen=25',pass1,'Your password can be 25 characters at most.')){return false;} 
	
	var pass2 = document.getElementById("pass2");
	if(pass1.value != pass2.value)
	{
		alert("Your password and confirm password do not match");
		return false;
	}
	
	document.getElementById("email").value = email.value;
	document.getElementById("first_name").value = firstname.value;
	document.getElementById("last_name").value = lastname.value;	
	document.registerform.submit();
}

function sfm_show_error_msg(msg,input_elmt)
{
    alert(msg);
	return false;
}

function validateInput(strValidateStr,objValue,strError) 
{ 
    var ret = true;
    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 
    switch(command) 
    { 
        case "req": 
        case "required": 
         { 
		   ret = TestRequiredInput(objValue,strError)
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
			 ret = TestMaxLen(objValue,cmdvalue,strError)
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
			 ret = TestMinLen(objValue,cmdvalue,strError)
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
				ret = TestInputType(objValue,"[^A-Za-z0-9]",strError, 
						objValue.name+": Only alpha-numeric characters allowed ");
				break; 
           }
        case "alnum_s": 
        case "alphanumeric_space": 
           { 
				ret = TestInputType(objValue,"[^A-Za-z0-9\.\\s]",strError, 
						objValue.name+": Only alpha-numeric characters and space allowed ");
				break; 
           }		   
        case "num": 
        case "numeric": 
           { 
                ret = TestInputType(objValue,"[^0-9]",strError, 
						objValue.name+": Only digits allowed ");
                break;               
           }
        case "dec": 
        case "decimal": 
           { 
                ret = TestInputType(objValue,"[^0-9\.]",strError, 
						objValue.name+": Only numbers allowed ");
                break;               
           }
        case "alphabetic": 
        case "alpha": 
           { 
                ret = TestInputType(objValue,"[^A-Za-z]",strError, 
						objValue.name+": Only alphabetic characters allowed ");
                break; 
           }
        case "alphabetic_space": 
        case "alpha_s": 
           { 
                ret = TestInputType(objValue,"[^A-Za-z\\s]",strError, 
						objValue.name+": Only alphabetic characters and space allowed ");
                break; 
           }
        case "email": 
          { 
			   ret = TestEmail(objValue,strError);
               break; 
          }
    }//switch 
	return ret;
}

function validateEmail(email)
{
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function IsCheckSelected(objValue,chkValue)
{
    var selected=false;
	var objcheck = objValue.form.elements[objValue.name];
    if(objcheck.length)
	{
		var idxchk=-1;
		for(var c=0;c < objcheck.length;c++)
		{
		   if(objcheck[c].value == chkValue)
		   {
		     idxchk=c;
			 break;
		   }//if
		}//for
		if(idxchk>= 0)
		{
		  if(objcheck[idxchk].checked=="1")
		  {
		    selected=true;
		  }
		}//if
	}
	else
	{
		if(objValue.checked == "1")
		{
			selected=true;
		}//if
	}//else	

	return selected;
}
function TestDontSelectChk(objValue,chkValue,strError)
{
	var pass = true;
	pass = IsCheckSelected(objValue,chkValue)?false:true;

	if(pass==false)
	{
     if(!strError || strError.length ==0) 
        { 
        	strError = "Can't Proceed as you selected "+objValue.name;  
        }//if			  
	  sfm_show_error_msg(strError,objValue);
	  
	}
    return pass;
}
function TestShouldSelectChk(objValue,chkValue,strError)
{
	var pass = true;

	pass = IsCheckSelected(objValue,chkValue)?true:false;

	if(pass==false)
	{
     if(!strError || strError.length ==0) 
        { 
        	strError = "You should select "+objValue.name;  
        }//if			  
	  sfm_show_error_msg(strError,objValue);
	  
	}
    return pass;
}

function TestRequiredInput(objValue,strError)
{
 var ret = true;
 var val = objValue.value;
 val = val.replace(/^\s+|\s+$/g,"");//trim
    if(eval(val.length) == 0) 
    { 
       if(!strError || strError.length ==0) 
       { 
         strError = objValue.name + " : Required Field"; 
       }//if 
       sfm_show_error_msg(strError,objValue); 
       ret=false; 
    }//if 
return ret;
}

function TestMaxLen(objValue,strMaxLen,strError)
{
 var ret = true;
    if(eval(objValue.value.length) > eval(strMaxLen)) 
    { 
      if(!strError || strError.length ==0) 
      { 
        strError = objValue.name + " : "+ strMaxLen +" characters maximum "; 
      }//if 
      sfm_show_error_msg(strError,objValue); 
      ret = false; 
    }//if 
return ret;
}

function TestMinLen(objValue,strMinLen,strError)
{
 var ret = true;
    if(eval(objValue.value.length) <  eval(strMinLen)) 
    { 
      if(!strError || strError.length ==0) 
      { 
        strError = objValue.name + " : " + strMinLen + " characters minimum  "; 
      }//if               
      sfm_show_error_msg(strError,objValue); 
      ret = false;   
    }//if 
return ret;
}

function TestInputType(objValue,strRegExp,strError,strDefaultError)
{
   var ret = true;

    var charpos = objValue.value.search(strRegExp); 
    if(objValue.value.length > 0 &&  charpos >= 0) 
    { 
     if(!strError || strError.length ==0) 
      { 
        strError = strDefaultError;
      }//if 
      sfm_show_error_msg(strError,objValue); 
      ret = false; 
    }//if 
 return ret;
}

function TestEmail(objValue,strError)
{
var ret = true;
     if(objValue.value.length > 0 && !validateEmail(objValue.value)	 ) 
     { 
       if(!strError || strError.length ==0) 
       { 
          strError = objValue.name+": Enter a valid Email address "; 
       }//if                                               
       sfm_show_error_msg(strError,objValue); 
       ret = false; 
     }//if 
return ret;
}

function imgresize(elem,maxw,maxh)
{
	if (elem == undefined || elem == null) return false;
	if (maxw == undefined) maxw = 50;
	if (maxh == undefined) maxh = 50;
	var orig_width = elem.width;
	var orig_height = elem.height;
	
	if (elem.width > elem.height) 
	{
		if(elem.width > maxw) 
		{ 
			elem.width = maxw; 
			elem.height = orig_height*(maxw/orig_width);
		}
	} 
	else 
	{
		if(elem.height > maxh) 
		{ 
			elem.height = maxh; 
			elem.width = orig_width*(maxh/orig_height);
		}
	}
	return true;
}

function letterfilter(letter)
{
	var loc = document.location.href;
	var updateuri = 0;
	if(loc.indexOf('?') != -1)
	{
		var hashes = loc.slice(loc.indexOf('?') + 1).split('&');     
		var varname = "";
		var varval = "";
		//alert(hashes);
		for(var i = 0; i < hashes.length; i++)    
		{        
			hash = hashes[i].split('=');
			varname = hash[0];
			varval = hash[1];
			//alert(varname+" = "+varval);
			if(varname == "let")
			{
				updateuri = 1;
				if(varval != "")
				{
					// change queryString with new one
					//alert(varval+" => "+qweery_append);
					loc = str_replace("let="+varval, "let="+letter,loc);
				}
				else
				{
					// var present, no value, add value
					loc = str_replace("let=","let="+letter,loc);
				}
				break;
			}
		}
	}
	
	if(updateuri == 0)
	{
		// was not present in uri, add it
		if(loc.indexOf('?') != -1)
		{
			// add it with &
			loc = loc+"&let="+letter;
		}
		else
		{
			// add it with ?
			loc = loc+"?let="+letter;
		}
	}
	document.location.href = loc;
}

function setWordFilter()
{
	var f = document.getElementById("listtype").value;
	var loc = document.location.href;
	var updateuri = 0;
	if(loc.indexOf('?') != -1)
	{
		var hashes = loc.slice(loc.indexOf('?') + 1).split('&');     
		var varname = "";
		var varval = "";
		//alert(hashes);
		for(var i = 0; i < hashes.length; i++)    
		{        
			hash = hashes[i].split('=');
			varname = hash[0];
			varval = hash[1];
			//alert(varname+" = "+varval);
			if(varname == "fil")
			{
				updateuri = 1;
				if(varval != "")
				{
					// change queryString with new one
					//alert(varval+" => "+qweery_append);
					loc = str_replace("fil="+varval, "fil="+f,loc);
				}
				else
				{
					// var present, no value, add value
					loc = str_replace("fil=","fil="+f,loc);
				}
				break;
			}
		}
	}
	
	if(updateuri == 0)
	{
		// was not present in uri, add it
		if(loc.indexOf('?') != -1)
		{
			// add it with &
			loc = loc+"&fil="+f;
		}
		else
		{
			// add it with ?
			loc = loc+"?fil="+f;
		}
	}
	document.location.href = loc;
}

function openword(wt,wid,tid,ai)
{
	if(wt == 0)
	{
		// from input
		wid = document.getElementById("newword").value;
	}
	
	wid = trim(wid);
	if(wid != "")
	{
		//new Ajax.Request('fetch-dictionary',   
		new Ajax.Request('?page_id=351',   
		{   method:'post',
			parameters: {wt: wt, wid:wid,tid:tid,ai:ai},
			onSuccess: function(transport)
			{       
				var response = transport.responseText;
				document.getElementById("wordedit").innerHTML = response;
			}
		});
	}
}

function setWordAction()
{
	var action = document.getElementById("action").value;
	if(action == "2")
	{
		// replace
		document.getElementById("trexpand").style.display = "none";
		document.getElementById("trreplace").style.display = "";
	}
	else if(action == "3")
	{
		// expand
		document.getElementById("trreplace").style.display = "none";
		document.getElementById("trexpand").style.display = "";
	}
	else
	{
		// show nothing
		document.getElementById("trexpand").style.display = "none";
		document.getElementById("trreplace").style.display = "none";
	}
}

function closeWordAction()
{
	document.getElementById("wordedit").innerHTML = "";
}

function deleteWord()
{
	document.getElementById('deletegroup').value = 0;
	var answer = confirm("Are you sure you want to delete this item");
	if(answer)
	{
		document.getElementById('deletegroup').value= 1;
		document.docForm.submit()
	}
	else
	{
		document.getElementById('deletegroup').value= 0;
	}
}

function setLanguage(lg)
{
	set_cookie ( "language", lg, 2030, 01, 01 );
	
	var locationwin = window.location.href;
	var updateuri = 1;
	if(locationwin.indexOf('?') != -1)
	{
		var hashes = locationwin.slice(locationwin.indexOf('?') + 1).split('&');     
		var varname = "";
		var varval = "";
		
		for(var i = 0; i < hashes.length; i++)    
		{        
			hash = hashes[i].split('=');
			varname = hash[0];
			varval = hash[1];
			
			if(varname == "lang")
			{
				if(varval != "")
				{
					if(lg == "en")
					{
						locationwin = str_replace("="+varval, "=en",locationwin);
						document.location.href = locationwin;
						updateuri = 0;
					}
					else if(lg == "nl")
					{
						locationwin = str_replace("="+varval, "=nl",locationwin);
						document.location.href = locationwin;
						updateuri = 0;
					}
				}
				else
				{
					if(lg == "en")
					{
						locationwin = str_replace("lang=","lang=en",locationwin);
						document.location.href = locationwin;
						updateuri = 0;
					}
					else if(lg == "nl")
					{
						locationwin = str_replace("lang=","lang=nl",locationwin);
						document.location.href = locationwin;
						updateuri = 0;
					}
				}
				break;
			}
		}
	}

	if(updateuri == 1)
	{
		// was not present in uri, add it
		if(locationwin.indexOf('?') != -1)
		{
			if(lg == "en")
			{
				locationwin = locationwin+"&lang=en";
				document.location.href = locationwin;
				updateuri = 0;
			}
			else if(lg == "nl")
			{
				locationwin = locationwin+"&lang=nl";
				document.location.href = locationwin;
			}
		}
		else
		{
			if(lg == "en")
			{
				locationwin = locationwin+"?lang=en";
				document.location.href = locationwin;
				updateuri = 0;
			}
			else if(lg == "nl")
			{
				locationwin = locationwin+"?lang=nl";
				document.location.href = locationwin;
			}
		}
	}
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function imgresize(elem,maxw,maxh)
{
	if (elem == undefined || elem == null) return false;
	if (maxw == undefined) maxw = 50;
	if (maxh == undefined) maxh = 50;
	var orig_width = elem.width;
	var orig_height = elem.height;
	
	if (elem.width > elem.height) 
	{
		if(elem.width > maxw) 
		{ 
			elem.width = maxw; 
			elem.height = orig_height*(maxw/orig_width);
		}
	}
	else if (elem.width == elem.height) 
	{
		if(elem.width > maxw) 
		{ 
			elem.width = maxw; 
			elem.height = orig_height*(maxw/orig_width);
		}
		else if(elem.height > maxh) 
		{ 
			elem.height = maxh; 
			elem.width = orig_width*(maxh/orig_height);
		}
	} 
	else 
	{
		if(elem.height > maxh) 
		{ 
			elem.height = maxh; 
			elem.width = orig_width*(maxh/orig_height);
		}
	}
	return true;
}

