var IE = false;
var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var mouseX, mouseY;
var it_ie = document.all;

if(document.getElementById){
	if(document.all) IE = true;
	else NS6 = true;	
} 
NS4 = (document.layers)?true:false;

function pop_err(fieldname,err_msg)
{
	fieldname.focus();
	alert(err_msg);
}

function trim(st)
{
	index = 0;
	for (var i = 0; i < st.length; i++)
	{
		ch = st.charAt(i);
		if (ch == ' ')
			index++;
		else 
			break;
	}
	st = st.substring(index, st.length);
	index = st.length;
	for (i = index-1; i > 0; i--)
	{
		ch = st.charAt(i);
		if (ch==' ')
			index--;
		else
			break;
	}
	st = st.substring(0, index);
	return st;
}

function check_url(str_url)
{
	var arr = new Array();
	var re = /[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*:\/\/([0-9a-zA-Z-_`!@$&*+|\]\[:;?,~=]+)+(\.[0-9a-zA-Z-_`!@$&*+|\]\[:;?,~=]+)*(\/[0-9a-z A-Z-_`!@$&*+|\]\[:;?,~.=]*)*$/;
	str_url = trim(str_url);
	if(str_url.search(re)){
		return false;
	} else{
		pos_pointslash = str_url.indexOf("./");
		pos_slashpoint = str_url.indexOf("/.");
		if(pos_pointslash != -1 || pos_slashpoint != -1)
			return false;
		arr = str_url.split("//");
		if(arr.length > 2)
			return false;
		return true;
	}
}
//set MD5 for password
function calculateValue() {
	var doc = document.frmLogin;
	var szPW = doc.password.value;
	szPW +=sharedValue;
	return calcValue(szPW);
}

function doLogin()
{
	var doc = document.frmLogin, m = "";
	if(doc.txt_username.value == ""){
		m += '- Please enter username login.\n';
	}
	if(doc.txt_password.value == ""){
		m += '- Please enter password login.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	//var szPW = calculateValue();
	//doc.strpassword.value=szPW;
	//doc.password.value="";
	return true;
}

function docheckall()
{
	var doc = document.frmList;
	var is_check = doc.chkall.checked;
	var numrec = doc.total_item.value;
	if(numrec > 0)
	{
		for(var i=0; i<doc.length; i++){
			if((doc.elements[i].type == "checkbox") && (doc.elements[i].name == "chkitem"))
				doc.elements[i].checked = is_check;
		}
		if(is_check){
			doc.cmdDelete.disabled = false;
		}else{
			doc.cmdDelete.disabled = true;
		}
		doc.cmdUpdate.disabled = true;
	}else{
		doc.cmdDelete.disabled = true;
	}
}

function docheckitem()
{
	var doc = document.frmList;
	var is_check = 0;
	for(var i=0; i<doc.length; i++){
		if(doc.elements[i].type == "checkbox" && doc.elements[i].checked == true && doc.elements[i].name != "chkall" && doc.elements[i].name != "chkactive")
			is_check = is_check + 1;
	}
	if(is_check > 0){
		doc.cmdDelete.disabled = false;
	}else{
		doc.cmdDelete.disabled = true;
	}
	if(is_check == 1)
		doc.cmdUpdate.disabled = false;
	else
		doc.cmdUpdate.disabled = true;
	if(is_check == doc.total_item.value)
		doc.chkall.checked = true;
	else
		doc.chkall.checked = false;
}

function getpositionmouse(evt)
{
	mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;		
}

function gmobj(mtxt){if(document.getElementById){m=document.getElementById(mtxt)}else if(document.all){m=document.all[mtxt]}else if(document.layers){m=document[mtxt]}return m;}

function itmovemouse(e){
	e = (window.event) ? window.event : e;
	if (it_isdrag){
	    gmobj('tipDiv').style.left = it_ie ? it_tx + event.clientX - it_x : it_tx + e.clientX - it_x;
	    gmobj('tipDiv').style.top  = it_ie ? it_ty + event.clientY - it_y : it_ty + e.clientY - it_y;
		//itfixframe();
		it_sticky = true;
	    return false;
	}
}

function itselectmouse(e){
	it_isdrag = true;
	e = (window.event) ? window.event : e;
	it_tx = parseInt(gmobj('tipDiv').style.left+0,10);
	it_ty = parseInt(gmobj('tipDiv').style.top+0,10);
	it_x = it_ie ? event.clientX : e.clientX;
	it_y = it_ie ? event.clientY : e.clientY;
	document.onmousemove=itmovemouse;
	return false;
}

function closealllayer()
{	
	document.frmList.reset()
	document.getElementById("tblAddNew").style.display= "none"
}

function doaddnewmenu()
{	
	document.getElementById("tblAddNew").style.display= "block"
}

function dosavemenu(stract)
{
	var doc = document.frmList, m = "";
	if(doc.txtMenuName.value == ""){
		m += '- Please enter menu name.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	doc.act.value = stract;
	doc.submit()
}

function doloadupdate()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.submit()
}

function delete_selected()
{
	var doc = document.frmList;
	doc.act.value = "Delete"
	doc.submit()	
}

function doeditpage(szid)
{
	var doc = document.frmList;
	doc.itemid.value = szid
	doc.action = "admin_page_content.asp"
	doc.submit()
}

function dosavecontent()
{
	var doc = document.frmList;
	doc.act.value = "SaveData"
	doc.submit()
}

function mod_delete_selected()
{
	var doc = document.frmList;
	doc.act.value = "Delete"
	doc.submit()
}

function update_active_selected()
{
	var doc = document.frmList, strchkactive = "", strcheck = "", struncheck = "";
	for(var i=0; i<doc.length; i++){
		if((doc.elements[i].type == "checkbox") && (doc.elements[i].name == "chkactive"))
		{
			if(doc.elements[i].checked == true)
			{
				strcheck = strcheck + "Y-" + doc.elements[i].value + "|"
			}else{
				struncheck = struncheck + "N-" + doc.elements[i].value + "|"
			}
		}
	}
	strchkactive = strcheck + struncheck
	doc.stractive.value = strchkactive;	
	doc.act.value = "Active";
	doc.submit()
	return;
}

function doloadupdate()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.submit()
}

function change_project()
{
	var doc = document.frmList;
	if (doc.cbm.value=="")
		{
			document.location.replace('project.asp')
		}
	else
		{
		doc.act.value = "Arrange"
		doc.submit()
		}
}

function viewdetailtest(szid)
{
	var doc = document.frmList;
	doc.itemid.value = szid;
	doc.act.value = "ViewTest"
	doc.submit()
}

function viewdetailorder(szid)
{	
	var doc = document.frmList;
	doc.itemid.value = szid;
	doc.act.value = "ViewOrder"
	doc.submit()
}

function closeviewtest()
{
	document.getElementById("tipDiv").style.visibility= "hidden";
}

function doaddnews()
{
	document.location.replace('add_news.asp')
}

function doadd_info()
{
	document.location.replace('admin_add_info.asp')
}



function doadd_detail_product()
{
	document.location.replace('admin_add_productdetail.asp')
}

function doaddimages()
{
	document.location.replace('add_images.asp')
}

function doloadupdateimages()
{
	var doc = document.frmList;
	doc.action = "update_images.asp"
	doc.submit()
}

function doloadupdatequantity()
{
	var doc = document.frmList;
	doc.action = "admin_update_quantity_price.asp"
	doc.submit()
}

function doloadupdate_info()
{
	var doc = document.frmList;
	doc.action = "admin_update_info.asp"
	doc.submit()
}
function doaddimg_promotion()
{
	document.location.replace('admin_add_img_promotion.asp')
}
function doaddimg_bk()
{
	document.location.replace('admin_add_img_bk.asp')
}

function doaddproduct()
{
	document.location.replace('admin_add_product.asp')
}
function doaddsizeproduct()
{
	document.location.replace('admin_add_size_product.asp')
}

function doadd_quantity()
{
	document.location.replace('admin_add_quantity_price.asp')
}


function doaddservices()
{
	document.location.replace('add_services.asp')
}

function doaddcategory()
{
	document.location.replace('admin_add_product_category.asp')
}


function dosavenewscontent()
{
	var doc = document.frmList, m = "";
	if(doc.txtTitle.value == ""){
		m += '- Please enter news title.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	doc.act.value = "SaveData"
	doc.submit()
}

function doloadupdatenews()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "update_news.asp"
	doc.submit()
}

function doloadupdateproduct()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "admin_update_product.asp"
	doc.submit()
}
function doloadupdateimg_promotion()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "admin_update_img_promotion.asp"
	doc.submit()
}
function doloadupdateimg_bk()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "admin_update_img_bk.asp"
	doc.submit()
}

function doloadupdatesizeproduct()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "admin_update_size_product.asp"
	doc.submit()
}



function doloadviewcontact()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "viewcontact.asp"
	doc.submit()
}

function doloadupdat_detail_product()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "admin_update_productdetail.asp"
	doc.submit()
}

function doloadupdateservices()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "update_services.asp"
	doc.submit()
}



function doloadupdatecategory()
{
	var doc = document.frmList;
	//doc.act.value = "Update"
	doc.action = "update_product_category.asp"
	doc.submit()
}

function loadmanageproduct()
{
	document.location.replace('admin_product.asp');
}


function loadmanegedetailproduct()
{
	document.location.replace('admin_productdetail.asp');
}

function loadmanagesize()
{
	document.location.replace('admin_size.asp');
}

function loadmanagequantity()
{
	document.location.replace('admin_quantity_price.asp');
}

function doloadupdatearticles()
{
	var doc = document.frmList;
	doc.act.value = "Update"
	doc.action = "admin_add_articles.asp"
	doc.submit()
}

function sendfeedback()
{
	var doc = document.frmProcess, m = "";
	if(doc.txtName.value == ""){
		m += '- Please enter your name.\n';
	}
	szemail = doc.txtEmail.value
	if(!isemailaddress(szemail))
	{
		m += '- Please enter your e-mail address.\n';
	}
	if(doc.txtComment.value == "")
	{
		m += '- Please enter your comment.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	var sBody = getRequestBody(doc);	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", doc.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				if(oXmlHttp.responseText == "OK")
				{					
					alert("Your feedback has been sent. Thank you!")
					doc.reset()
				}								
			} else {
				alert("An error occurred: " + oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);
}

function sendtechtips()
{
	var doc = document.frmProcess, m = "";
	if(doc.txtName.value == ""){
		m += '- Please enter your name.\n';
	}
	szemail = doc.txtEmail.value
	if(!isemailaddress(szemail))
	{
		m += '- Please enter your e-mail address.\n';
	}
	if(doc.txtComment.value == "")
	{
		m += '- Please enter your comment.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	var sBody = getRequestBody(doc);	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", doc.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				if(oXmlHttp.responseText == "OK")
				{					
					alert("Your Tech & Tips has been sent. Thank you!")
					doc.reset()
				}								
			} else {
				alert("An error occurred: " + oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);
}

function sendbidrequest()
{
	var doc = document.frmProcess, m = "";
	if(doc.txtName.value == ""){
		m += '- Please enter your name.\n';
	}
	szemail = doc.txtEmail.value
	if(!isemailaddress(szemail))
	{
		m += '- Please enter your e-mail address.\n';
	}
	if(doc.txtComment.value == "")
	{
		m += '- Please enter your comment.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	var sBody = getRequestBody(doc);	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", doc.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				if(oXmlHttp.responseText == "OK")
				{					
					alert("Your Bidding Request has been sent. Thank you!")
					doc.reset()
				}								
			} else {
				alert("An error occurred: " + oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);
}

function sendquoterequest()
{
	var doc = document.frmProcess, m = "";
	if(doc.txtName.value == ""){
		m += '- Please enter your name.\n';
	}
	szemail = doc.txtEmail.value
	if(!isemailaddress(szemail))
	{
		m += '- Please enter your e-mail address.\n';
	}
	szURL = doc.txtWebsite.value
	if(szURL != "")
	{
		if(!check_url(szURL))
		{
			m += '- Please enter your website is false.\n';
		}
	}
	if(doc.chksample.checked == true)
	{
		doc.chksample.value = 1
	}else
	{
		doc.chksample.value = 0
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}	
	var sBody = getRequestBody(doc);	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", doc.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				if(oXmlHttp.responseText == "OK")
				{					
					alert("Your quote request has been sent. Thank you!")
					doc.reset()
				}								
			} else {
				alert("An error occurred: " + oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);
}

function sendorder()
{
	var doc = document.frmProcess, m = "";
	if(doc.txtName.value == ""){
		m += '- Please enter your name.\n';
	}
	if(doc.txtAddress.value == ""){
		m += '- Please enter your address.\n';
	}
	szemail = doc.txtEmail.value
	if(!isemailaddress(szemail))
	{
		m += '- Please enter your e-mail address.\n';
	}	
	if(doc.txtComment.value == ""){
		m += '- Please enter your product comment.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	var sBody = getRequestBody(doc);	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", doc.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				if(oXmlHttp.responseText == "OK")
				{					
					alert("Your order has been sent. Thank you!")
					doc.reset()
				}								
			} else {
				alert("An error occurred: " + oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);
}

function LoadAddHomeSeo()
{
	var doc = document.frmList;
	doc.act.value = "LoadAddLink"
	doc.submit()
}

function dosavelinkhome()
{
	var doc = document.frmList, m = "";
	if(doc.txtLinkName.value == ""){
		m += '- Please enter link name.\n';
	}	
	if(doc.txtURLLink.value == "")
	{
		m += '- Please enter URL Link.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	doc.act.value = "SaveAddLink"
	doc.submit()
}

function doupdate_sang()
{	
	var doc = document.frmList;
	doc.act.value = "sasa"
	doc.submit()
}



function dosavesearchhome()
{
	var doc = document.frmList;
	doc.act.value = "SaveSearchHome"
	doc.submit()
}

function LoadUpdateHomeSeo()
{
	var doc = document.frmList;
	doc.act.value = "LoadUpdateLink"
	doc.submit()
}

function AddNewAdvs()
{
	document.location.replace('admin_add_advs.asp')
}

function cancel_add_advs()
{
	document.location.replace('admin_advs.asp')
}

function check_data()
{
	var doc = document.frmAdv, m = "";
	if(doc.txtAdvName.value == "")
	{
		m += '- Please enter advertisement name.\n';
	}
	if(doc.txtURL.value == "")
	{
		m += '- Please enter URL Link.\n';
	}
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	return;
}

function UpdateAdvs()
{
	var doc = document.frmList;
	doc.action = "admin_update_advs.asp"
	doc.submit()
}

function viewnews(szid)
{	
	var sBody = "itemid=" + szid + "&act=GetNews";	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", 'process.asp', true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {				
				document.getElementById("tipDiv").innerHTML = oXmlHttp.responseText
				document.getElementById("tipDiv").style.left = mouseX
				document.getElementById("tipDiv").style.top = mouseY
				document.getElementById("tipDiv").style.visibility= "visible";
			} else {
				alert("An error occurred: " + oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);
}

function closeviewpopuphome()
{
	document.getElementById("tipDiv").style.visibility= "hidden";
}

function viewarticles(szid)
{	
	var sBody = "itemid=" + szid + "&act=GetArticles";	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", 'process.asp', true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {				
				document.getElementById("tipDiv").innerHTML = oXmlHttp.responseText
				document.getElementById("tipDiv").style.left = mouseX
				document.getElementById("tipDiv").style.top = mouseY
				document.getElementById("tipDiv").style.visibility= "visible";
			} else {
				alert("An error occurred: " + oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);
}

function check_form()
{
	var doc = document.frmTechsupport, m = "";
	if(doc.txt_contact_person.value == ""){
		m += '- Please enter Contact Person Name.\n';
	}
	if(doc.txt_company_name.value == ""){
		m += '- Please enter Company Name.\n';
	}
	if(doc.txt_email_add.value == ""){
		m += '- Please enter Your E-mail.\n';
	}
	
	if(doc.txt_email_add.value != ""){
		if(!isemailaddress(doc.txt_email_add.value)){
		m+='- Email wrong format.\n';}
	}
		
	
	if(doc.txt_problem_error.value == ""){
		m += '- Please enter Problem Error.\n';
	}
	if(doc.sl_urgency_status.value == ""){
		m += '- Please Select Urgency Status.\n';
	}
	
			
	if(m) {
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
}

//ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt


//Decription: check valid email address
//@param emailStr(string) : email string input
//@param return(boolean)
function isEmail(emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	//alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    //alert("The username doesn't seem to be valid.")
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        //alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid.")
    return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   //alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   //alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}



function checkNumber(s){
		if (s!="")
		{
			var str=".,0123456789"; 
			for(var j=0;j<str.length;j++)
			if(str.indexOf(s.charAt(j))==-1){								
				return false;
			}		  	
		}
		return true;
	}	
//-------------------------------------------------------------------
function getURLParam(strParamName)
{
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 )
	{
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0 ;iParam < aQueryString.length ;iParam++ )
		{
			if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 )
			{
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
return strReturn;
}
function OpenWindow(theURL)
 { 
	var winName="PopUp";
	var features="toolbar=no,location=no,status=yes,scrollbars=no,width=700,height=600top=150,left=150"
  window.open(theURL,winName,features);
}

function FromTextArea(str)
{
	while(str.indexOf("\n")!=-1)
	{
		str=str.replace("\n","<br>");
	}
	
	return str;
}
function ToTextArea(str)
{
	while(str.indexOf("<br>")!=-1)
	{
		str=str.replace("<br>","\n");
	}
	
	return str;
}

function check_form()

{ 
ob = document.getElementById("txtname"); 
 if (ob.value=="") {
  alert("Name cannot blank");
  ob.focus();
  return false;
 } 
 
///////////////email///////////////
 ob = document.getElementById("txtemail"); 
 if (ob.value=="") {
  alert("Email Address cannot blank");
  ob.focus();
  return false;
 } 
 if (!isEmail(ob.value)) {
  alert("Please enter a vaild Email Address");
  ob.focus();
  return false;
 }
}

function check_add_new()
{
	//new
	ob = document.getElementById("txt_title"); 
 	if (ob.value=="") {
  		alert("Title cannot blank");
  		ob.focus();
  		return false;
 	} 


	ob = document.getElementById("txt_short_news"); 
 	if (ob.value=="") {
  		alert("Short content cannot blank");
  		ob.focus();
  		return false;
 	} 

	ob = document.getElementById("ImageUpload"); 
 	if (ob.value=="") {
  		alert("Image for this news cannot blank");
  		ob.focus();
  		return false;
 	} 
	
	//services
	
}

function check_update_new()
{
	
	ob = document.getElementById("txt_title"); 
 	if (ob.value=="") {
  		alert("Title cannot blank");
  		ob.focus();
  		return false;
 	} 


	ob = document.getElementById("txt_short_news"); 
 	if (ob.value=="") {
  		alert("Short content cannot blank");
  		ob.focus();
  		return false;
 	} 

	

}

function check_add_services()
{
ob = document.getElementById("txt_name_services"); 
 	if (ob.value=="") {
  		alert("Name of services cannot blank");
  		ob.focus();
  		return false;
 	}
}

function check_add_category()
{
	ob = document.getElementById("txt_name"); 
 	if (ob.value=="") {
  		alert("Name of Category cannot blank");
  		ob.focus();
  		return false;
 	}
}

function check_add_product()
{
	ob = document.getElementById("txt_name"); 
 	if (ob.value=="") {
  		alert("Name Require!");
  		ob.focus();
  		return false;
 	}
	ob = document.getElementById("txt_page"); 
 	if (ob.value=="") {
  		alert("Page Catalog Require!");
  		ob.focus();
  		return false;
 	}
	chk = document.getElementById("label");
	if (chk.value!="update"){
		ob = document.getElementById("ImageUpload"); 
 		if (ob.value=="") {
  			alert("Image Require!");
  			ob.focus();
  			return false;
 	}
	}
}

function check_update_project()
{
	ob = document.getElementById("slect_category"); 
 	if (ob.value=="0") {
  		alert("Select one Category, please.");
  		ob.focus();
  		return false;
 	}
	ob = document.getElementById("txt_name"); 
 	if (ob.value=="") {
  		alert("Name of Project cannot blank.");
  		ob.focus();
  		return false;
 	}
	ob = document.getElementById("txt_short_intro"); 
 	if (ob.value=="") {
  		alert("Short content of Project cannot blank.");
  		ob.focus();
  		return false;
 	}
	ob = document.getElementById("txt_weight"); 
 	if (ob.value=="") {
  		alert("Weight of Project cannot blank.");
  		ob.focus();
  		return false;
 	}
	
}


function check_add_image()
{
	ob = document.getElementById("ImageUpload"); 
 	if (ob.value=="") {
  		alert("Please select a image for Showroom.");
  		ob.focus();
  		return false;
 	}

}



//-----------------------------------

function CheckNumber01(number)
{
	var pattern = "0123456789.";
	var len = number.value.length;
	if (len != 0)
	{
		var index = 0;
		
		while ((index < len) && (len != 0))
			if (pattern.indexOf(number.value.charAt(index)) == -1)
			{
				if (index == len-1)
					number.value = number.value.substring(0, len-1);
				else if (index == 0)
					 	number.value = number.value.substring(1, len);
					 else number.value = number.value.substring(0, index)+number.value.substring(index+1, len);
				index = 0;
				len = number.value.length;
			}
			else index++;
	}
}

function chk()
{
	if	(document.frmlist.chk_info.checked)
		{
			document.getElementById("info_div").style.display= "inline";
			document.getElementById("info_div_file").style.display= "inline";
			document.getElementById("info_div_comment").style.display= "inline";
		}
	else
			document.getElementById("info_div").style.display= "none";
			document.getElementById("info_div_comment").style.display= "none";
			document.getElementById("info_div_file").style.display= "none";
}

function chk01()
{
var ctr;
 ctr=document.getElementsByName("rd_check");

 for(j=0;j<ctr.length;j++){
  if(ctr[j].checked==true){   
   id = ctr[j].value;
  }
 }

if (id=="file")
	{	//document.getElementById('theform').innerHTML='<form'+ 'action="admin_add_productdetail_detail.asp" method="post" enctype="multipart/form-data" name="frmlist">';
		document.getElementById("info_div_file").style.display= "inline";
		document.getElementById("info_div_comment").style.display= "none";
		//document.location.replace('register_new.html');
	}
if (id=="comment")
	{	
		//document.getElementById("theform").innerText= "<form gfgfggf>";
		document.getElementById("info_div_comment").style.display= "inline";
		document.getElementById("info_div_file").style.display= "none";
	}

}

function CheckNumber(number)
{
	var pattern = "0123456789.";
	var len = number.value.length;
	if (len != 0)
	{
		var index = 0;
		
		while ((index < len) && (len != 0))
			if (pattern.indexOf(number.value.charAt(index)) == -1)
			{
				if (index == len-1)
					number.value = number.value.substring(0, len-1);
				else if (index == 0)
					 	number.value = number.value.substring(1, len);
					 else number.value = number.value.substring(0, index)+number.value.substring(index+1, len);
				index = 0;
				len = number.value.length;
			}
			else index++;
	}
}




//----------------------------------------------------
function hien()
{
	if (document.getElementById("tipDiv").style.visibility == "hidden")
	{
		document.getElementById("tipDiv").style.visibility= "visible";
		
	}
	else
		closeviewpopuphome1();
		//document.getElementById("tipDiv").style.visibility= "hidden";

	
}