/*
 * GoMidjets JS Functions File
 * Copyright (C) GoMidjets Ltd.
 * www.GoMidjets.com
 */


/*
 * Price Calculation
 */
function CalculatePrice(int1,int2)
{
        //alert('calc ' + int)
		// The next line executes the php and sends the 'k' as paramater . 'data' is the return value from the php;
        $.post("js/ajax_calc_price.php", { k: int1, j: int2 },
  		function(data){
		    //alert('data ->' + data);
			
		data = data.split('||');
		//data[0] is price
		//data[1] is md5 code
		//data[2] is VOBs quantity
		//data[3] is years
		//data[4] is original price
		//data[5] is discount description
						
//      document.getElementById('goPrice').innerHTML = 'Price is USD $' + data[0] +'<br /> <a target="_blank" href="https://www.plimus.com/jsp/buynow.jsp?contractId=2278070&overridePrice=' + data[0] + '&bCur=USD&opp=' + data[1] + '">Click here to purchase</a>';
		// link should be:https://www.plimus.com/jsp/buynow.jsp?contractId=2278070&overridePrice=<data>&bCur=USD&opp=<m5dValue>
		
		//alert('data4->'+data[4]);
		if (!is_null(data[4]))
		{
			// Discount!
			myDiscount = data[4] - data[0];
			myDiscount = myDiscount.toFixed(2);
			//document.getElementById('goPrice').innerHTML = 'Licensing cost for ' + data[2] + ' VOBs for ' + data[3] + ' year(s)	 is: USD $ ' + data[4] + ' &nbsp; <br /><strong>But wait! You are getting a discount!</strong><br /> Original Price: USD $<del>' + data[4] + '</del><br /> You Pay: USD $'+ data[0] + '<br /> <font color="blue">You Save: USD $' + myDiscount + ' (' + data[5] + ') </font><a onclick="tSendMail(' + data[2] + ',' + data[3] + ');" target="_blank" href="https://www.plimus.com/jsp/buynow.jsp?contractId=2278070&overridePrice=' + data[0] + '&bCur=USD&opp=' + data[1] + '"><img src="images/btn_buy.jpg"></a>';
			document.getElementById('goPrice').innerHTML = 'Licensing cost for ' + data[2] + ' VOBs for ' + data[3] + ' years	 is: USD $ ' + data[4] + ' &nbsp; <br /> List Price: USD $<del>' + data[4] + '</del><br /> Price: USD $'+ data[0] + '<br /> <font color="blue">You Save: USD $' + myDiscount + ' (' + data[5] + ') </font><a onclick="tSendMail(' + data[2] + ',' + data[3] + ');" target="_blank" href="https://www.plimus.com/jsp/buynow.jsp?contractId=2278070&overridePrice=' + data[0] + '&bCur=USD&opp=' + data[1] + '"><img src="images/btn_buy.jpg"></a>';
			
		}
		else
		{
			// Link
			document.getElementById('goPrice').innerHTML = 'Licensing cost for ' + data[2] + ' VOBs for ' + data[3] + ' year	 is: USD $' + data[0] + ' &nbsp; &nbsp; &nbsp; &nbsp; <a onclick="tSendMail(' + data[2] + ',' + data[3] + ');" target="_blank" href="https://www.plimus.com/jsp/buynow.jsp?contractId=2278070&overridePrice=' + data[0] + '&bCur=USD&opp=' + data[1] + '"><img src="images/btn_buy.jpg"></a>';
		}
        MM_changeProp('goPrice','','display','block','DIV')
        MM_effectAppearFade('goPrice', 1000, 0, 100, false)
  });

}

/*
 * Send Email
 */
function tSendMail(vob,years)
{
	$.post("js/ajax_calc_price.php", { a: 'dom', b: vob, c: years },
	function(data){
		//alert('data->'+data);
  	});
		
}

<!--
function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}
//-->

function MM_effectAppearFade(targetElement, duration, from, to, toggle)
{
        Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}



/*
 * Integer Only
 */
function checkIt(evt) 
{
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true;
}

/*
 * Check for null vars
 */
function is_null(myVar)
{
	if (myVar == "" || myVar == null || myVar.charAt(0) == ' ')
	{
		return true;
	}
	else
	{
		return false;
	}
	
}



/*
 * Email Validation
 */
function isValidEmail(strEmail) {
validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if (strEmail.search(validRegExp) == -1) {return false;} 
	return true;
}


/*
 * Quick Contact Validation
 */
function GoMidjets_QuickContact_Form_Validate()
{
	// Get Vars
	name = document.GoMidjets_QuickContact_Form.qcontact_name.value;
	company = document.GoMidjets_QuickContact_Form.qcontact_company.value;
	email = document.GoMidjets_QuickContact_Form.qcontact_email.value;
	phone = document.GoMidjets_QuickContact_Form.qcontact_phone.value;
	message = document.GoMidjets_QuickContact_Form.qcontact_comments.value;
	
	// Name
	if (is_null(name))
	{
		alert('You must fill in your name');
		document.GoMidjets_QuickContact_Form.qcontact_name.focus();
		return false;
	}

	// Company
	if (is_null(company))
	{
		alert('You must fill in your company name');
		document.GoMidjets_QuickContact_Form.qcontact_company.focus();
		return false;
	}

	// Email
	if (is_null(email))
	{
		alert('You must fill in your email address');
		document.GoMidjets_QuickContact_Form.qcontact_email.focus();
		return false;
	}

	// Email Validation
	if (!isValidEmail(email))
	{
		alert('Invalid E-mail. please fill in correct one.');
		document.GoMidjets_QuickContact_Form.qcontact_email.focus();
		return false;		
	}
	
	// Phone
	if (is_null(phone))
	{
		alert('You must fill in your phone number');
		document.GoMidjets_QuickContact_Form.qcontact_phone.focus();
		return false;
	}
	
	// Submit
        $.post("js/ajax_quick_contact.php", { l: name, i: company, o: email, r: phone, g: message},
  		function(data){
			//alert('data->'+data)
			if (data == '1')
			{
				// Remove Contact Form
				MM_effectAppearFade('store_quick_contact', 1000, 100, 0, false);
				window.setTimeout("MM_changeProp('store_quick_contact','','display','none','DIV')",1000);
	
				// Show Thank You
				window.setTimeout("MM_effectAppearFade('store_quick_contact_thankyou', 1000, 0, 100, false)	",1200);
				window.setTimeout("MM_changeProp('store_quick_contact_thankyou','','display','block','DIV')",2200); // Just incase...	
		    
			}
		  });	
		
}

/*
 * Registration Validation
 */

function GoMidjets_Registration_Form_Validate()
{

	// Get Vars
	txt_fname = document.frm_GoMidjetsRegister.txt_fname.value;
	txt_lname = document.frm_GoMidjetsRegister.txt_lname.value;
	txt_email = document.frm_GoMidjetsRegister.txt_email.value;
	txt_password = document.frm_GoMidjetsRegister.txt_password.value;
	txt_password2 = document.frm_GoMidjetsRegister.txt_password2.value;
	sec_code = document.frm_GoMidjetsRegister.txt_sec_code.value;
	
	// First Name
	if (is_null(txt_fname))
	{
		alert('You must fill in your first name');
		document.frm_GoMidjetsRegister.txt_fname.focus();
		return false;
	}

	// Last Name
	if (is_null(txt_lname))
	{
		alert('You must fill in your last name');
		document.frm_GoMidjetsRegister.txt_lname.focus();
		return false;
	}

	// Email
	if (is_null(txt_email))
	{
		alert('You must fill in your email address');
		document.frm_GoMidjetsRegister.txt_email.focus();
		return false;
	}

	// Email Validation
	if (!isValidEmail(txt_email))
	{
		alert('Invalid E-mail. please fill in correct one.');
		document.frm_GoMidjetsRegister.txt_email.focus();
		return false;		
	}

	// Password1
	if (is_null(txt_password))
	{
		alert('You must fill in your password');
		document.frm_GoMidjetsRegister.txt_password.focus();
		return false;
	}	
	
	// Password2
	if (is_null(txt_password2))
	{
		alert('You must fill in your password again');
		document.frm_GoMidjetsRegister.txt_password2.focus();
		return false;
	}
	
	// Password1 Vs. Password2
	if (txt_password != txt_password2)
	{
		alert('Your Passwords does not match. please retype.');
		document.frm_GoMidjetsRegister.txt_password.focus();
		return false;
	}	
	
	// Security Code
	if (is_null(sec_code))
	{
		alert('You must fill in a security code');
		document.frm_GoMidjetsRegister.txt_sec_code.focus();
		return false;
	}	
	
	return true;
	/*submit*/
	//document.frm_GoMidjetsRegister.submit();		

}


/*
 * Price Quote Form Validation
 */

function GoMidjets_GetQuote_Form_Validate()
{

	// Get Vars
	txt_name = document.frm_GoMidjetsQuote.txt_name.value;
	txt_company = document.frm_GoMidjetsQuote.txt_company.value;
	txt_email = document.frm_GoMidjetsQuote.txt_email.value;
	txt_phone = document.frm_GoMidjetsQuote.txt_phone.value;

	
	// First Name
	if (is_null(txt_name))
	{
		alert('You must fill in your name');
		document.frm_GoMidjetsQuote.txt_name.focus();
		return false;
	}

	// Company
	if (is_null(txt_company))
	{
		alert('You must fill in your company name');
		document.frm_GoMidjetsQuote.txt_company.focus();
		return false;
	}

	// Email
	if (is_null(txt_email))
	{
		alert('You must fill in your email address');
		document.frm_GoMidjetsQuote.txt_email.focus();
		return false;
	}

	// Email Validation
	if (!isValidEmail(txt_email))
	{
		alert('Invalid E-mail. please fill in correct one.');
		document.frm_GoMidjetsQuote.txt_email.focus();
		return false;		
	}

	// Phone
	if (is_null(txt_phone))
	{
		alert('You must fill in your phone number');
		document.frm_GoMidjetsQuote.txt_phone.focus();
		return false;
	}

	
	// Security Code
//	if (is_null(sec_code))
//	{
//		alert('You must fill in a security code');
//		document.frm_GoMidjetsRegister.txt_sec_code.focus();
//		return false;
//	}	
	
	return true;
	/*submit*/
	//document.frm_GoMidjetsRegister.submit();		

}


/* Form Validate - Registration */
/*
function GoMidjets_Registration_Form_Validate(formobj){
	
	// Enter name of mandatory fields
	var fieldRequired = Array("txt_fname", "txt_lname", "txt_email","txt_password","txt_password2","sec_code",);
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("First Name", "Last Name", "E-Mail","Password","Password Verification","Security Code");
	
	// dialog message
	var alertMsg = "You must provide the following details:\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
*/




function GoMidjets_PasswordRecovery_Form_Validate()
{
	// Get Vars
	txt_email = document.frm_GoMidjetsPasswordRecovery.txt_email.value;
	sec_code = document.frm_GoMidjetsPasswordRecovery.txt_sec_code.value;
	
	// Email
	if (is_null(txt_email))
	{
		alert('You must fill in your email');
		document.frm_GoMidjetsPasswordRecovery.txt_email.focus();
		return false;
	}
	
	// Email Validation
	if (!isValidEmail(txt_email))
	{
		alert('Invalid E-mail. please fill in correct one.');
		document.frm_GoMidjetsPasswordRecovery.txt_email.focus();
		return false;		
	}
	
	// Security Code
	if (is_null(sec_code))
	{
		alert('You must fill in a security code');
		document.frm_GoMidjetsPasswordRecovery.txt_sec_code.focus();
		return false;
	}		

	/*submit*/
	document.frm_GoMidjetsPasswordRecovery.submit();	
}


function GoMidjets_PasswordChange_Form_Validate()
{
	// Get Vars
	txt_password = document.frm_GoMidjetsPasswordChange.txt_password.value;
	txt_password2 = document.frm_GoMidjetsPasswordChange.txt_password2.value;
	
	// Password1
	if (is_null(txt_password))
	{
		alert('You must fill in your password');
		document.frm_GoMidjetsPasswordChange.txt_password.focus();
		return false;
	}	
	
	// Password2
	if (is_null(txt_password2))
	{
		alert('You must fill in your password again');
		document.frm_GoMidjetsPasswordChange.txt_password2.focus();
		return false;
	}
	
	// Password1 Vs. Password2
	if (txt_password != txt_password2)
	{
		alert('Your Passwords does not match. please retype.');
		document.frm_GoMidjetsPasswordChange.txt_password.focus();
		return false;
	}		
	

	/*submit*/
	document.frm_GoMidjetsPasswordChange.submit();		
}






// Validate Login
function GoMidjets_Login_Form_Validate()
{

	// Get Vars
	txt_email = document.frm_GoMidjetsLogin.txt_email.value;
	txt_password = document.frm_GoMidjetsLogin.txt_password.value;
	
	// Email
	if (is_null(txt_email))
	{
		alert('You must fill in your email');
		document.frm_GoMidjetsLogin.txt_email.focus();
		return false;
	}	
	// Email Validation
	if (!isValidEmail(txt_email))
	{
		alert('Invalid E-mail. please fill in correct one.');
		document.frm_GoMidjetsLogin.txt_email.focus();
		return false;		
	}
		
	// Password
	if (is_null(txt_password))
	{
		alert('Please fill in your password');
		document.frm_GoMidjetsLogin.txt_password.focus();
		return false;
	}	
	

	/*submit*/
	//document.frm_GoMidjetsLogin.submit();
			
}
