
var ns = (document.layers) ? true : false;
var ie = (document.all) ? true : false;
var v_specWin = null;

//=============================================================================
// window
//=============================================================================

function setHomePage (src)
{
    src.style.behavior = 'url(#default#homepage)';
    src.setHomePage('http://www.b2plast.com');
}

function addFavorite (src)
{
    window.external.AddFavorite(location.href, document.title);
}

function initPage ()
{
    //openOnTop();
}

function openOnTop ()
{
    if (top.location != self.location)
        top.location = self.location;
}

function openWindow (url, m_name, params)
{
	v_specWin = window.open(url, m_name, params);
	v_specWin.focus();
}

function closeWindow ()
{
	window.close();
}

function setDocument (url)
{
	document.location = url;
}

function printDocument () 
{
	window.print();
}

function openLink (url)
{
	openWindow(url, '', 'toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes');
}

function openFloat (url)
{
	openWindow(url, '', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=520, height=520');
}

function openPrint (url)
{
	openWindow(url + '&print=1', '', 'toolbar=yes, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes');
}

// open a link from a new window navigate in opener and close window
function backToParent (navRef)
{
    if (window.opener && !window.opener.closed)
        window.opener.location.href = navRef;
    window.close();
}

function resizeWindow (width, height)
{
    winLeft   = window.screenLeft;
    winTop    = window.screenTop;
    winWidth  = window.screen.width;
    winHeight = window.screen.height - 30;

    newWidth  = Math.min(winWidth, width);
    newHeight = Math.min(winHeight, height);

    if ((winLeft + newWidth) > winWidth)
        newLeft = winWidth - newWidth;
    else
        newLeft = winLeft;
        
    if ((winTop + newHeight) > winHeight)
        newTop = winHeight - newHeight;
    else
        newTop = winTop;
        
	window.moveTo(newLeft, newTop);
	window.resizeTo(newWidth, newHeight);
}

//=============================================================================
// close spec window
//=============================================================================


function closeSpec(){

if(v_specWin && !v_specWin.closed) 
    {
    v_specWin.close();
    }
}

//===============================================
// jump to url
//===============================================

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//===============================================
//deramweaver scripts
//===============================================
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) { //v3.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); 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];}
}



//===============================================
// Cookies
//===============================================

function getCookie(name) 
{ 
    var prefix = name + "=" ;
    var cookieStartIndex = document.cookie.indexOf(prefix) ;

    if (cookieStartIndex == -1) return null ;

    var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);

    if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length ;

    return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)) ;

}

//var nnn="zname";

//if(getCookie(nnn)) document.writeln("Hello, "+getCookie(nnn)+"!");

//else document.writeln("Hello, Visitor!");


//==================================
//date
//==================================
function grtDate()
{
ff= new Date();  var mmonth;  if (ff.getMonth()==0){mmonth="January";}

if (ff.getMonth()==1){mmonth="February";} if (ff.getMonth()==2){mmonth="March";} 

if (ff.getMonth()==3){mmonth="April";}  if (ff.getMonth()==4){mmonth="May";}

 if (ff.getMonth()==5){mmonth="June";} if (ff.getMonth()==6){mmonth="July";}

 if (ff.getMonth()==7){mmonth="August ";}  if (ff.getMonth()==8){mmonth="September";}

 if (ff.getMonth()==9){mmonth="October";}  if (ff.getMonth()==10){mmonth="November ";}

 if (ff.getMonth()==11){mmonth="December";}  document.writeln(mmonth + "&nbsp;" + ff.getDate() +",&nbsp;"+ff.getYear());   
}


//=============================================================================
// query
//=============================================================================

function queryStringPageId ()
{
    queryVar = this.location.href;
    inq      = queryVar.indexOf('?');
    queryVar = queryVar.substring(inq + 1);

    i = queryVar.indexOf('PageId');
    k = queryVar.indexOf('&');

    if (k>0)
    {
        queryVar = queryVar.substring(queryVar.indexOf('=') + 1);
        k = queryVar.indexOf('&');
        return queryVar.substring(0,k);
    }
    else
        return queryVar.substring(queryVar.indexOf('=') + 1);

}


function queryStringValue (name)
{
    queryVar = this.location.href;
    inq      = queryVar.indexOf('?');
    queryVar = queryVar.substring(inq + 1);

    if (inq > 0)
    {
        text1     = '&';
        strLength = queryVar.length;
        txtLength = text1.length;

        i = queryVar.indexOf(text1);

        while (i + txtLength < strLength)
        {
        	if (i > 0)
        		querySplit(queryVar.substring(0, i), '=');
        	else
        		querySplit(queryVar, '=');

        	queryVar = queryVar.substring(i + txtLength, strLength);
		
		if (queryVar.substring(0, queryVar.indexOf('=')) == name)
			return queryVar.substring(queryVar.indexOf('=') + 1);


        	var i = queryVar.indexOf(text1);

        	if (i < 1)
        		i = strLength + 1;
        }

        querySplit(queryVar, '=');
    }
}



function queryString ()
{
    queryVar = this.location.href;
    inq      = queryVar.indexOf('?');
    queryVar = queryVar.substring(inq + 1);

    if (inq > 0)
    {
        text1     = '&';
        strLength = queryVar.length;
        txtLength = text1.length;

        i = queryVar.indexOf(text1);

        while (i + txtLength < strLength)
        {
        	if (i > 0)
        		querySplit(queryVar.substring(0, i), '=');
        	else
        		querySplit(queryVar, '=');

        	queryVar = queryVar.substring(i + txtLength, strLength);
        	var i = queryVar.indexOf(text1);

        	if (i < 1)
        		i = strLength + 1;
        }

        querySplit(queryVar, '=');
    }
}

function querySplit (string, text)
{
	name  = string.substring(0, string.indexOf(text));
	value = string.substring(string.indexOf(text) + 1);
	eval('query_' + name + ' = unescape(value);');
}

//=============================================================================
// images
//=============================================================================

function imagesPreload ()
{
    var d = document; 

    if (d.images)
    {
        if(!d.MM_p)
            d.MM_p = new Array();
        var i;
        var j = d.MM_p.length;
        var a = imagesPreload.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 imageRestore ()
{
    var i;
    var x;
    var a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
        x.src = x.oSrc;
}

function imageSwap ()
{
    var i;
    var j = 0;
    var x;
    var a = imageSwap.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3)
    if ((x = findObject(a[i])) != null)
    {
        document.MM_sr[j++] = x;
        if(!x.oSrc)
            x.oSrc = x.src; 
        x.src = a[i + 2];
    }
}

function findObject (n, d)
{
    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 = findObject(n, d.layers[i].document);
    if (!x && document.getElementById)
        x = document.getElementById(n); 
    return x;
}

//=============================================================================
// mouse
//=============================================================================

var mouseX  = 0;
var mouseY  = 0;

function activateMouse ()
{
    window.onload = function()
    {
        if (ns)
            document.captureEvents(Event.MOUSEMOVE);
        document.onmousemove = getMousePosition;
    }
}

function getMousePosition (e)
{
    if (ns)
    {
        mouseX = e.pageX;
        mouseY = e.pageY;
    }
    else 
    {
        mouseX = event.clientX;
        mouseY = event.clientY;
    }
    return true;
}

//======================================================================
// form validation
//======================================================================

function validateDownload ()
{
	var warning = "";
	//alert("valitade!");
    if (isEmpty(downloadForm.fname))
    {
        warning = 'First name is empty!';
    }
    if (isEmpty(downloadForm.lname))
    {
        warning = warning + '\nLast name is empty!';
    }  
    if (isEmpty(downloadForm.email))
        warning = warning + '\nE-mail is empty!';
    else if (! isEmail(downloadForm.email))                  
		warning = warning + '\nE-mail is incorrect!';
       
    
    if (warning != "")
    {
		alert(warning);
        return false;
    }
    
	downloadForm.btn_submit.disabled = true;
	return true;
        
}

function validateRegForm ()
{
	var warning = "";
	//alert("valitade!");
    if (isEmpty(regForm.fname))
    {
        warning = 'First name is empty!';
    }
    if (isEmpty(regForm.lname))
    {
        warning = warning + '\nLast name is empty!';
    }  
    if (isEmpty(regForm.email))
        warning = warning + '\nE-mail is empty!';
    else if (! isEmail(regForm.email))                  
		warning = warning + '\nE-mail is incorrect!';
       
    
    if (warning != "")
    {
		alert(warning);
        return false;
    }
    
	regForm.btn_submit.disabled = true;
	return true;
        
}

function validateInqiry ()
{
	var warning = "";
	//alert("valitade!");
    if (isEmpty(inquiryForm.fname))
    {
        warning = 'First name is empty!';
    }
    if (isEmpty(inquiryForm.lname))
    {
        warning = warning + '\nLast name is empty!';
    }  
    if (isEmpty(inquiryForm.email))
        warning = warning + '\nE-mail is empty!';
    else if (! isEmail(inquiryForm.email))                  
		warning = warning + '\nE-mail is incorrect!';
       
    
    if (warning != "")
    {
		alert(warning);
        return false;
    }
    
	inquiryForm.btn_submit.disabled = true;
	return true;
        
}


function validateContact ()
{
	var warning="";
    if (isEmpty(formContact.email))
    {
        warning = 'Email is empty';
        //return false;
    }
    if (isEmpty(formContact.contact_name))
    {
        warning = warning + '\nContact name is empty';
        //return false;
    }
    if (warning != "")
    {
		alert(warning);
        return false;
    }
    
	formContact.btn_submit.disabled = true;
	return true;
}

function validateLogin ()
{

    if (isEmpty(loginForm.contact_name))
    {
        alert('Contact Name is empty');
        return false;
    }
    if (isEmpty(loginForm.user_pw))
    {
        alert('Password is empty');
        return false;
    }
    
    loginForm.btn_submit.disabled = true;

    return true;
}

function validateChangePass ()
{

    if (isEmpty(passForm.user_pw))
    {
        alert('Old password is empty!');
        return false;
    }
    if (isEmpty(passForm.user_pw_new) || isEmpty(passForm.user_pw_new2))
    {
        alert('New Password Or confirm password is empty!');
        return false;
    }
    
    if (! (isEqual (passForm.user_pw_new, passForm.user_pw_new2)))
    {
        alert('New Password and confirm password are not identical!');
        return false;
    }
    
    passForm.btn_submit.disabled = true;

    return true;
}

function validateForgotPass ()
{

    if (isEmpty(passForgotForm.contact_name))
    {
        alert('Contact name is empty!');
        return false;
    }
    if (isEmpty(passForgotForm.email))
    {
        alert('E-mail is empty!');
        return false;
    }
        
    passForgotForm.btn_submit.disabled = true;

    return true;
}

function validateReg ()
{
	var warning = "";
	
    if (isEmpty(RegForm.company))
    {
        warning = 'Company Name name is empty!';
    }
    if (isEmpty(RegForm.contact_name))
    {
        warning = warning + '\nContact name is empty!';
    }
    if (isEmpty(RegForm.email))
    {
        warning = warning + '\nE-mail is empty!';
    }
    if (isEmpty(RegForm.phone_country_code))
    {
        warning = warning + '\nPhone country code is empty!';
    }
    if (isEmpty(RegForm.phone_area_code))
    {
        warning = warning + '\nPhone area code is empty!';
    }
    if (isEmpty(RegForm.phone_number))
    {
        warning = warning + '\nPhone number is empty!';
    }
    
    
    if (warning != "")
    {
		alert(warning);
        return false;
    }
    //get activities and interests
    
	RegForm.btn_submit.disabled = true;
	return true;
        
}

function oncheck(){

	if(RegForm.products[7].checked){ 
		for(i=0; i<7; i++) RegForm.products[i].checked=false;
	}
}

function oncheck1(){

RegForm.products[7].checked=false;

}


function checkProducts_OLD(checkList){
	if(checkList.length > 0)
		{		
		var checkArray = new Array();
		checkArray = checkList.split(",");
		var i;
		var j = checkArray.length;
		var t 
		
		for (i = 0; i < checkArray.length; i++)
		    {
		        t = (checkArray[i] -1);
				RegForm.products[t].checked=true;
		    }
		}
}

function checkProducts(checkList){
	if(checkList.length > 0)
		{		
		var checkArray = new Array();
		checkArray = checkList.split(",");
		var i;
		var j = checkArray.length;
		var t 

		for (i = 0; i < checkArray.length; i++)
		    {
		    t = (checkArray[i] );
				for (x = 0; x < RegForm.products.length; x++)
				{ 
					if (RegForm.products[x].value==t)
					{
						RegForm.products[x].checked=true ;
					}
				}
			 }
		}
}

function checkActivities(checkList){
	if(checkList.length > 0)
	{		
	var checkArray = new Array();
	checkArray = checkList.split(",");
	var i;
	var j = checkArray.length;
	var t 
				
	for (i = 0; i < checkArray.length; i++)
	    {
	    t = (checkArray[i] );
			for (x = 0; x < RegForm.main_activities.length; x++)
			{
				if (RegForm.main_activities[x].value==t)
				{
					RegForm.main_activities[x].checked=true ;
				}
			}
		 }
	}
}

//=============================================================================
// popup
//=============================================================================

var popupItem;
var popupShowEdge = 0;
var popupHideEdge = -374;

function popupInit ()
{
    popupItem = (ns) ? document.getElementById('popup_menu').style : document.all.popup_menu.style;
}

function popupShow ()
{
    if (window.doHide)
        clearInterval(doHide)
    doShow = setInterval('popupShowEngine()', 4);
}

function popupHide ()
{
    clearInterval(doShow);
    doHide = setInterval('popupHideEngine()', 4);
}

function popupShowEngine ()
{
    if (ie && popupItem.pixelTop < popupShowEdge)
        popupItem.pixelTop += 5;
    else if (ns && parseInt(popupItem.top) < popupShowEdge)
        popupItem.top = parseInt(popupItem.top) + 2;
    else if (window.doShow)
        clearInterval(doShow);
}

function popupHideEngine ()
{
    if (ie && popupItem.pixelTop > popupHideEdge)
        popupItem.pixelTop -= 5;
    else if (ns && parseInt(popupItem.top) > popupHideEdge)
        popupItem.top = parseInt(popupItem.top) - 2;
    else if (window.doHide)
        clearInterval(doHide);
}

