/*--------------------------------------------------
Please declare all javascript functions that needed
inside this global.js
--------------------------------------------------*/


function adjustPosition(imgHeight,img,container){
var containerHeight=parseFloat(document.getElementById(container).style.height);
var desiredTop=(containerHeight/2)-(imgHeight/2);
img.style.marginTop=desiredTop;
}

function back(){
window.location="index.php?mod=ps";
}

function checkPrice(price){
var result=isNumeric(price);

if(price==""){
	window.alert("This field cannot be empty");
	//document.getElementById("updateButton").disabled=true;
	document.getElementById("updateButton").style.visibility="hidden";
}else{
	//document.getElementById("updateButton").disabled=false;
	document.getElementById("updateButton").style.visibility="visible";
}

if(price!=""&&!result){
	window.alert("Price must be in Numeric form");
	//document.getElementById("updateButton").disabled=true;
	document.getElementById("updateButton").style.visibility="hidden";
}else{
	//document.getElementById("updateButton").disabled=false;
	document.getElementById("updateButton").style.visibility="visible";
}

}

function isNumeric(vTestValue)
{
	// put the TEST value into a string object variable
	var sField = new String(vTestValue);
	
	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}
	
	// made it through the loop - we have a number
	return true;
}

function wordRemain(compInfo, doc)
{
var remainText=100-compInfo.length;
     doc.value = remainText;
}

function checkTarget(targetType){
	if(targetType=="merchant"){
	document.productForm.publicPrice.style.backgroundColor="#636363";
	document.productForm.publicPrice.disabled=true;
	document.productForm.publicPrice.value="";
	document.productForm.merchantPrice.style.backgroundColor="white";
	document.productForm.merchantPrice.disabled=false;
	document.productForm.merchantPrice.value="<?echo $merchantPrice?>";
	}else if(targetType=="public"){
	document.productForm.merchantPrice.style.backgroundColor="#636363";
	document.productForm.merchantPrice.disabled=true;
	document.productForm.merchantPrice.value="";
	document.productForm.publicPrice.style.backgroundColor="white";
	document.productForm.publicPrice.disabled=false;
	document.productForm.publicPrice.value="<?echo $publicPrice?>";
	}else{
	document.productForm.merchantPrice.style.backgroundColor="white";
	document.productForm.merchantPrice.disabled=false;
	document.productForm.merchantPrice.value="<?echo $merchantPrice?>";
	document.productForm.publicPrice.style.backgroundColor="white";
	document.productForm.publicPrice.disabled=false;
	document.productForm.publicPrice.value="<?echo $publicPrice?>";
	}
}

function checkDisplayType(selectType){
	if(selectType=="yes"){
	document.getElementById('displayOption').style.display="";
	document.getElementById('target').style.display="";
	}else if(selectType=="no"){
	document.getElementById('displayOption').style.display="none";
	document.getElementById('target').style.display="";
	}else{
	
	}
}

	function checkAdvanceDisplay(advTargetType){
	if(advTargetType=="1"){
	document.productForm.weight.style.backgroundColor="white";
	document.productForm.weight.disabled=false;
	document.productForm.weight.value="<?echo $weight?>";
		if(document.productForm.target.value=="merchant"){
			document.productForm.merchantPrice.style.backgroundColor="white";
			document.productForm.merchantPrice.disabled=false;
			document.productForm.merchantPrice.value="<?echo $merchantPrice?>";
		}else if(document.productForm.target.value=="public"){
			document.productForm.publicPrice.style.backgroundColor="white";
			document.productForm.publicPrice.disabled=false;
			document.productForm.publicPrice.value="<?echo $publicPrice?>";
		
		}else{
			document.productForm.merchantPrice.style.backgroundColor="white";
			document.productForm.merchantPrice.disabled=false;
			document.productForm.merchantPrice.value="<?echo $merchantPrice?>";
			document.productForm.publicPrice.style.backgroundColor="white";
			document.productForm.publicPrice.disabled=false;
			document.productForm.publicPrice.value="<?echo $publicPrice?>";
		}
	}else if(advTargetType=="2"){
	document.productForm.weight.style.backgroundColor="#636363";
	document.productForm.weight.disabled=true;
	document.productForm.weight.value="";
		if(document.productForm.target.value=="merchant"){
			document.productForm.merchantPrice.style.backgroundColor="white";
			document.productForm.merchantPrice.disabled=false;
			document.productForm.merchantPrice.value="<?echo $merchantPrice?>";
		}else{
			document.productForm.publicPrice.style.backgroundColor="white";
			document.productForm.publicPrice.disabled=false;
			document.productForm.publicPrice.value="<?echo $publicPrice?>";
		}
	}else if(advTargetType=="3"){
	document.productForm.weight.style.backgroundColor="white";
	document.productForm.weight.disabled=false;
	document.productForm.weight.value="<?echo $weight?>";
	document.productForm.merchantPrice.style.backgroundColor="#636363";
	document.productForm.merchantPrice.disabled=true;
	document.productForm.merchantPrice.value="";
	document.productForm.publicPrice.style.backgroundColor="#636363";
	document.productForm.publicPrice.disabled=true;
	document.productForm.publicPrice.value="";
		
	}else if(advTargetType=="4"){
	document.productForm.weight.style.backgroundColor="#636363";
	document.productForm.weight.disabled=true;
	document.productForm.weight.value="";
		if(document.productForm.target.value=="merchant"){
			document.productForm.merchantPrice.style.backgroundColor="#636363";
			document.productForm.merchantPrice.disabled=true;
			document.productForm.merchantPrice.value="";
		}else{
			document.productForm.publicPrice.style.backgroundColor="#636363";
			document.productForm.publicPrice.disabled=true;
			document.productForm.publicPrice.value="";
		}
	}
}

function CommentRedirect()
{
var ans=confirm('Please register or login to post comments and enquiries. Do you wish to register an free public account?');
if (ans == true)
  {
    //alert('Yes');
   window.location = "http://www.malaysiab2c.my/index.php?mod=rgs"; 
   } 
}







