// Common Functions //

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ResetEmailType(form_type) {

	document.email_form.button_1.value=form_type;
	document.email_form.submit();
}

// Admin Functions //

function MemberLogin() {
   var message="",count=0;		
   if (document.sb_login.sb_compref.value == "") {
      count += 1;
      message += "Please enter Company Reference!\n";
   }
   if (document.sb_login.sb_staff.value == "") {
      count += 1;
      message += "Please enter Staff Name!\n";
   }
   if (document.sb_login.sb_password.value == "") {
      count += 1;
      message += "Please enter Password!\n";
   }
   if (count > 0) {
      alert(message);	
      return false;
   }
   else	{
      document.sb_login.submit();
   }
}

function CompanyUpdate() {
   var message="",count=0;		
   if (document.company_modify.comp_name.value == "")	{
      count += 1;
      message += "Please enter company name!\n";
   }
   if (count > 0)										{
      alert(message);	
      return false;										}
   else {
      document.company_modify.submit();
   }
}


// Popup Function //
function previewRefresh(noMake)		{
	if(noMake)
	previewURL="http://www.smart-biz.ws/client/iconzept/";
	else
	previewURL="http://www.smart-biz.ws/client/iconzept/";
	document.main.location.replace(previewURL);
}

function dwl_popupDialog(target, arg, width, height, isModeless)
{
	if(!width) width=400;
	if(!height) height=400;
	if(!arg) arg="";
	
	myStyle = "font-family:Verdana; font-size:10; dialogWidth:" + width +"px; dialogHeight:"+ height + "px";
	
	// Add kill cache time
	myTime = new Date(); 
	if(target.indexOf("?")>0)
		target+="&xkct=" + myTime.getTime();
	else
		target+="?xkct=" + myTime.getTime();
		
	if(isModeless == true)	
		return showModelessDialog(target, arg, myStyle);
	else
		return showModalDialog(target, arg, myStyle);
}

function dwl_popupFrameDialog(title, myUrl, arg, width, height, isModeless)
{
	if(!width) width=400;
	if(!height) height=400;
	if(!arg) arg="";
	//myUrl = "/dwlib/dwl_iframe.phtml?target=" + escape(target) + "&title="+ escape(title);
	return dwl_popupDialog(myUrl, arg, width, height, isModeless)
}

	
function win_popup(choice,choice_action,width,height,section_id)		{
var w,h,winl,wint;
w=width;	h=height;	winl = (screen.width - w) / 2;	wint = (screen.height - h) / 2;
popWindow = window.open('popup.php?setting=' + choice + '&setting_action=' + choice_action + '&sb_section_id=' + section_id + '', 'winpopup', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + w +',height=' + h +',left=' + winl +',top=' + wint +'');
//var res=dwl_popupFrameDialog('Header Setting', 'popup.php?setting=' + choice + '&setting_action=' + choice_action + '','',width,height);
//var res=dwl_popupFrameDialog('Header Setting', 'http://manager.diysite.com/wsb/app/design/tasks/changeAttributes.phtml?flag=T','',width,height);
//if(res) previewRefresh();
}

function imageoversize_popup(imgID,imgWidth,imgHeight)		{
var w,h,winl,wint;
w=imgWidth;	h=imgHeight;	winl = (screen.width - w) / 2;	wint = (screen.height - h) / 2;
popWindow = window.open('product_detail.php?imgID=' + imgID + '', 'imgpopup', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + w +',height=' + h +',left=' + winl +',top=' + wint +'');

}

function image_popup(imgID,imgWidth,imgHeight)		{
var w,h,winl,wint;
w=imgWidth;	h=imgHeight;	winl = (screen.width - w) / 2;	wint = (screen.height - h) / 2;
popWindow = window.open('product_detail.php?imgID=' + imgID + '', 'imgpopup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + w +',height=' + h +',left=0,top=0');

}



function dwl_DialogResize(formDiv)
{
	return;
	if(formDiv.offsetHeight<=0 || formDiv.offsetWidth<=0) return; // Check
		
	resizeWnd=window;
	if(parent && parent.window)
	{
		resizeWnd=parent.window;
	}
	resizeWnd.dialogHeight = (formDiv.offsetHeight + 80) +"px" ;
	resizeWnd.dialogWidth =  (formDiv.offsetWidth  + 80) +"px";
}

function onSubmitOk()	{
			document.all.submit_ok.style.cursor = "wait";
			document.body.style.cursor = "wait";
			if(typeof(dwl_ifSubmitOk) != "undefined") {
				ret=dwl_ifSubmitOk();
			} else {
				ret=true;
			}
			document.all.submit_ok.style.cursor = "";
			document.body.style.cursor = "";
			return(ret);
}		


function onSubmitCancel()
		{
			if(typeof(dwl_ifSubmitCancel) != "undefined") {
				return(dwl_ifSubmitCancel());
			} else {
				if(parent) {
					parent.window.close();
				} else {
					window.close();
				}
				return(false);
			}
		}	
		
	
function showColor(val) {
document.compheaderfont.headerheading_font_color.value = val;
}

function closewin(URL) {
window.opener.parent.main.location.href=URL;
}

