﻿/*
#==============================================================================#
# Unit Name: YCSMain.js                                                        #
# Author:    Valentin Green - Yahalom Creative Solutions Ltd.                  #
# Date: 01.07.2008                                                             #
# Purpose: Hold main data and functions for the corresponding site             #
#==============================================================================#
# History:                                                                     #
# Ver      Date     Name   Description                                         #
# 1.xx   00.00.00 yyyyyy   z                                                   #
# 1.00   01.07.08 valieg   Creation of the unit                                #
#==============================================================================#
*/
/* if the browser is not W3C compliant,...bye */
    var W3CDOM = ( ( document.createElement != null) && ( document.getElementsByTagName != null)) ? true : false;
/* constants section */

/* globals section*/
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------

function sendMail() {

	var oCallback = {
		success: function (oResponse) {
			sendMailResponseHandler(oResponse.responseText);
        },

		failure: function (oResponse) {
			sendMailResponseHandler("An error occurred: " + oResponse.statusText);
		}
    };
	/* It seem that we need this workaround in order to handle the:
	** "YUI asyncRequest post with 'Length required' error on IIS6 + FireFox" bug,
	** alt least for YUI 2.4.1
	*/
	var sPostData = encodeURI(arguments[0]);
	YAHOO.util.Connect.asyncRequest('POST', 'sendContact.php', oCallback, sPostData);

}; //sendMail()

function sendMailResponseHandler(sMessage) {

	try {
		var oTmp = document.getElementById('frmContactID');
		if (oTmp) {
			oTmp.reset();
			document.location.href = 'thanks.html';
		};
	} catch (x) {
		alert("sendMailResponseHandler() - Email sending failure!"+'\n'+sMessage);
		return;
	};

}; //sendMailResponseHandler()

function MsgBox()
{
	var txt = arguments[0] + " function failure !\n";
	txt += "Error description: " + arguments[1].description + "\n";
	txt += "Click OK to continue.\n";
	alert(txt);

}; //MsgBox()

function TBFGreplacer () {
//.arguments[0]  supposed to be the working string
//.arguments[1]  supposed to be the searching tag ( string)
//.arguments[2]  supposed to be the "replace to..." pattern
//.arguments[3]  supposed to be 1 or N replacements flag
//
	if (arguments[3] = null) {
		re = new RegExp(arguments[1]);
		arguments[0] = arguments[0].replace(re, arguments[2]);
	} else {
		re = new RegExp(arguments[1], "g");
		arguments[0] = arguments[0].replace(re, arguments[2]);
	};

	return arguments[0];

} //TBFGreplacer ()

function trim12 (str) {

	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);

}; //trim12()

function SubmitWrapper () {

	var oTmp = new ycsFormValidator();

	if (oTmp.isValidForSubmit) {
		sendMail(oTmp.PostData)
	} else {
		alert(oTmp.AlertData);
	};
	oTmp = null;

}; //SubmitWrapper ()

ycsFormValidator = function () {

	var sTmp = null;
	var oTmp = null;

	this.isValidForSubmit = false;
	this.AlertData = 'Please review:\n\n';
	this.PostData = '';

	oTmp = document.getElementById(this.FormFields[0][0]);
	if (oTmp) {
		sTemp = this.trim12(oTmp.value);
		if (YAHOO.lang.isString(sTemp) && sTemp.length > 0) {
			this.isValidForSubmit = true;
			this.PostData += '&'+this.FormFields[0][1]+'='+sTemp;
		} else {
			//this.isValidForSubmit = false;
			this.AlertData += 'Name field. Must be filled out!\n';
		};
	};

	oTmp = document.getElementById(this.FormFields[1][0]);
	if (oTmp) {
		sTemp = this.trim12(oTmp.value);
		if (this.isPhone(sTemp)) {
			this.isValidForSubmit = true;
			this.PostData += '&'+this.FormFields[1][1]+'='+sTemp;
		} else {
			this.isValidForSubmit = false;
			this.AlertData += 'Invalid phone number. Must be filled out(10 digits)!\n';
		};
	};

	oTmp = document.getElementById(this.FormFields[2][0]);
	if (oTmp) {
		sTemp = this.trim12(oTmp.value);
		if (this.isEmail(sTemp)) {
			this.isValidForSubmit = true;
			this.PostData += '&'+this.FormFields[2][1]+'='+sTemp;
		} else {
			this.isValidForSubmit = false;
			this.AlertData += 'Invalid Email address. Must be filled out!\n';
		};
	};

	oTmp = document.getElementById(this.FormFields[3][0]);
	if (oTmp) {
		sTemp = oTmp.value;
		if (YAHOO.lang.isString(sTemp) && sTemp.length > 0) {
			this.isValidForSubmit = true;
			this.PostData += '&'+this.FormFields[3][1]+'='+sTemp;
		} else {
			this.isValidForSubmit = false;
			this.AlertData += 'No message!\n';
		};
	};

}; //ycsFormValidator

ycsFormValidator.prototype.FormFields = [['frmNameTxtID', 'frmNameTxt'],
										 ['frmPhoneTxtID', 'frmPhoneTxt'],
										 ['frmEmailTxtID', 'frmEmailTxt'],
										 ['frmMessageTxtID', 'frmMessageTxt']];


/**
 * Returns the formated number or '' string
 * @method fixToValue
 * @param  {number} number The number (from record fields)
 * @return {number}        The number, or null
 */

ycsFormValidator.prototype.isPhone = function(sPhone) {

    //valieg 27.08.2007 - don't check the "+" at the begining
    //phoneRegExp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
    phoneRegExp = /^((\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
	if (!YAHOO.lang.isString(sPhone)) {
		// error
		return false;
	};

    return phoneRegExp.test(sPhone);

}; //ycsFormValidator.prototype.isPhone

ycsFormValidator.prototype.isEmail = function(sEmail) {

    emailRegExp = /^[0-9a-z\._]+@[0-9a-z]+\..+$/i;
	if (!YAHOO.lang.isString(sEmail)) {
		// error
		return false;
	};

    return emailRegExp.test(sEmail);

}; //ycsFormValidator.prototype.isEmail

ycsFormValidator.prototype.trim12 = function() {

	var	str = arguments[0].replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);

}; //ycsFormValidator.prototype.trim12

function showLink () {

	var URL = null;

	if (!YAHOO.lang.isObject(arguments[0])) {
		// Error
		alert('Wrong parameter passed to showLink ()!');
		return;
	} else {
		var o = arguments[0];
		if (!YAHOO.lang.isObject(o.parentNode)) {
			// Error
			alert('Wrong parent node!');
			return;
		} else {
			var tmpID = o.parentNode.id;
			if (YAHOO.lang.isString(tmpID) && tmpID.length > 0) {
				// Ok. Let's parse the string
				tmpID = trim12(tmpID);
				tmpID = TBFGreplacer(TBFGreplacer(tmpID, 'ID', ""), 'press', "");
				switch (1*tmpID) {
					case 0:
						// 
						//URL = '';
						return;
						//break;

					case 1:
						// 
						URL = 'http://www.themarker.com/tmc/article.jhtml?ElementId=skira20080123_947374&origin=ibo&strToSearch=%E0%E9%EA%2C%F6%E5%EC%E7%E9%ED%2C%EE%F4%E5%EC%FA%2C%E1%F9%EC%E5%ED';
						break;

					case 2:
						// 
						URL = 'http://www.themarker.com/tmc/article.jhtml?ElementId=skira20071001_908501&origin=ibo&strToSearch=%E0%E2%E7%2C%E6%E1%EC';
						break;

					case 3:
						// 
						URL = 'http://www.themarker.com/tmc/article.jhtml?ElementId=skira20080120_946200&origin=ibo&strToSearch=%E0%E2%E7%2C%E6%E1%EC';
						break;

					case 4:
						// 
						URL = 'http://www.themarker.com/tmc/article.jhtml?ElementId=skira20080124_947685&origin=ibo&strToSearch=%E0%E2%E7%2C%E6%E1%EC';
						break;

					case 5:
						// 
						URL = 'http://www.themarker.com/tmc/article.jhtml?ElementId=skira20080113_944152&origin=ibo&strToSearch=%EE%E4%2C%E9%F9%2C%EC%EB%ED%2C%E1%FA%E9%F7%2C%E4%E4%F9%F7%F2%E5%FA';
						break;

					case 6:
						// 
						URL = 'http://www.themarker.com/tmc/article.jhtml?ElementId=skira20080113_944156&origin=ibo&strToSearch=%EB%EE%E4%2C%EE%F1%E5%EB%F0%FA%2C%F7%E5%F4%FA%2C%E4%E2%EE%EC%2C%F9%EC%EB%ED';
						break;

					case 7:
						// 
						URL = 'http://www.bizportal.co.il/shukhahon/biznews02.shtml?mid=170990&strsrh';
						break;

					case 8:
						// 
						URL = 'http://markets.themarker.com/tmc/article.jhtml?ElementId=ym20080611_94&layer=hp&layer2=&layer3=market';
						break;
			    };

				document.location.href = URL;

			} else {
				// Error
				alert('Wrong ID!');
				return;
			};
		};
	};

	return;

}; //showLink ()

function openZoomWin() {

	var URL = "";
	var name = "_blank";
/*
  var specs = "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400";
*/
	var specs = "titlebar=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no";
	var replace = false;

	switch (arguments[0]) {
		case 0:
			// VIBE-130 left pic
			//URL = "../../img/Zoom_vibe130left.jpg";
			URL = "../../inc/zoom01.html";
			specs += ", width=266, height=400, top=20, left=20";
			break;

		case 1:
			// VIBE-130 right pic
			//URL = "../../img/Zoom_vibe130Right.jpg";
			URL = "../../inc/zoom02.html";
			specs += ", width=214, height=400, top=0, left=20";
			break;

		case 2:
			// Diamond Count
			//URL = "../../img/Zoom_Counter.jpg";
			URL = "../../inc/zoom03.html";
			specs += ", width=461, height=400, top=20, left=20";
			break;

		case 3:
			// M-Count
			//URL = "../../img/Zoom_MCounter.jpg";
			URL = "../../inc/zoom04.html";
			specs += ", width=461, height=400, top=20, left=20";
			break;

		case 99:
			// Flash upgrade
			document.location.href = "inc/upgrade_flash.html";
			break;
	};

	try {
		window.open(URL, name, specs, replace);
	} catch(err) {
		MsgBox("openZoomWin()", err);
	};

}; //openZoomWin()

