/* checkout.PHP */
function sameAsAbove()
{
	var frm = document.frmCheckout;
	if(frm.chkSameAsAbove.checked==true)
	{
		document.getElementById("divShippingAddress").style.display = "none";
	}
	else
	{
		document.getElementById("divShippingAddress").style.display = "";
	}
}
function checkSameAsAbove(same)
{
	var frm = document.frmCheckout;
	if(same == 1)
	{
		sameAsAbove();
	}
}
/* viewimage.php, showimage.php*/
function resize()
{
	var a = document.getElementById('image_');
	var width=a.width+80;
	var height = a.height+110;
	window.resizeTo(width,height);
}

/* showportfolio.php*/
function openWindowShow(id)
{
	var url = "showimage.php?image="+id;
	window.open(url,"Image","height=500,width=500,scrollbars=yes");
}
/* product_details.php*/
function openWindowView(id,type)
{
	var url = "";
	
	if (type == 0)
		{
			url = "viewimage.php?id="+id;
		}
	else
		{
			url = "viewimage.php?bid="+id;
		}
	
	window.open(url,"Image","height=500,width=500,scrollbars=yes");
}
/* hd.php */
function changeLanguageHeader(langId)
{
	document.frmLang.lang_id.value = langId;
	document.frmLang.submit();
}
function changeCurrencyHeader(curId)
{
	document.frmCurrencyType.currency_type.value = curId;
	document.frmCurrencyType.submit();
}
/* functions.php, giftcoupon_payment.php, cashondelivery_payment.php, success.php */
function showAlertAndRedirect(message,newlocation)
{
	alert(message);
	location.href=newlocation;
}
/* pay.php */
function submitPaypalRequest()
{
	document.frmPayment.submit();
}
/* viewcart.php */
function redirectToPage(newlocation)
{
	location.href=newlocation;
}
/* company_search.php*/
function showPhoneNumber(i) 
{
	var divPhoneNumber = document.getElementById("divPhoneNumber"+i);
	var text = document.getElementById("displayText"+i);
	divPhoneNumber.style.display = "block";
	text.style.display = "none";
}

function sendClickRequest(object_type,object_id,user_id,click_type)
{
	if (window.XMLHttpRequest) 
	{
		http = new XMLHttpRequest();
	} 
	else 
		if (window.ActiveXObject) 
		{
			http = new ActiveXObject("Msxml2.XMLHTTP");
			if (!http) 
			{
				http = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}

	var url = "http://www.mall-bucuresti.ro/postclick.php";
	var params = "object_type="+object_type+"&object_id="+object_id+"&user_id="+user_id+"&click_type="+click_type;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
}
/*==================================================================
validfirstchars(string,allowedstring) : Returns true if first charcter of the string is a allowed character.
==================================================================
*/	 
function validfirstchars(strstring,allowedchar){
	    var start_do_name_char;
		var fFlag=false;
        start_do_name_char=strstring.charAt(0);	
        for (j = 0;  j <allowedchar.length; j++){
              if (start_do_name_char == allowedchar.charAt(j)){
			     fFlag=true;
			     break;
			  }   
        }		
        if (!fFlag){
		      return false;
	 	}
		return true;
}
/*==================================================================
validchars(string,allowedstring) : Returns true if all the string character is a allowed character.
==================================================================
*/	
function validchars(strstring,allowedchar,strl){
	            var ch;
				strstring=trim(strstring);
				if(strstring.length>strl){
				   return false;
				}   
		        for (i = 1;  i < strstring.length;i++){
							ch = strstring.charAt(i);
							for (j = 0;  j < allowedchar.length;  j++)
							   if (ch == allowedchar.charAt(j))
								    break;
									
							   if (j == allowedchar.length){
							        return false;
									break;
							   }
                }
	       return true;
}

function checkNumber(t) {
	if(t.value.length == 0 ||  isNaN(t.value) || t.value.substr(0,1) == " " || parseInt(t.value) < 0) {
		t.value="";
	}
}

function checkMail(email)
{
        var str1=email;
        var arr=str1.split('@');
        var eFlag=true;
        if(arr.length != 2)
        {
                eFlag = false;
        }
        else if(arr[0].length <= 0 || arr[0].indexOf(' ') != -1 || arr[0].indexOf("'") != -1 || arr[0].indexOf('"') != -1 || arr[1].indexOf('.') == -1)
        {
                        eFlag = false;
        }
        else
        {
                var dot=arr[1].split('.');
                if(dot.length < 2)
                {
                        eFlag = false;
                }
                else
                {
                        if(dot[0].length <= 0 || dot[0].indexOf(' ') != -1 || dot[0].indexOf('"') != -1 || dot[0].indexOf("'") != -1)
                        {
                                eFlag = false;
                        }

                        for(i=1;i < dot.length;i++)
                        {
                                if(dot[i].length <= 0 || dot[i].indexOf(' ') != -1 || dot[i].indexOf('"') != -1 || dot[i].indexOf("'") != -1 || dot[i].length > 4)
                                {
                                        eFlag = false;
                                }
                        }
                }
        }
                return eFlag;
}